jdk/src/jdk.unsupported/share/classes/sun/misc/Unsafe.java
author psandoz
Mon, 12 Jun 2017 14:30:40 -0700
changeset 45635 56b0672b0070
parent 45518 4a116dd82fb5
permissions -rw-r--r--
8181442: Deprecate sun.misc.Unsafe.defineClass Reviewed-by: shade, mchung
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
45518
4a116dd82fb5 8181292: Backport Rename internal Unsafe.compare methods from 10 to 9
psandoz
parents: 44359
diff changeset
     2
 * Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2707
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2707
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2707
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2707
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2707
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package sun.misc;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
36628
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
    28
import jdk.internal.vm.annotation.ForceInline;
35271
amurillo
parents: 35253 34882
diff changeset
    29
import jdk.internal.misc.VM;
42707
6059f74bacdf 8171377: Add sun.misc.Unsafe::invokeCleaner
chegar
parents: 38774
diff changeset
    30
import jdk.internal.ref.Cleaner;
37363
329dba26ffd2 8137058: Clear out all non-Critical APIs from sun.reflect
chegar
parents: 36966
diff changeset
    31
import jdk.internal.reflect.CallerSensitive;
329dba26ffd2 8137058: Clear out all non-Critical APIs from sun.reflect
chegar
parents: 36966
diff changeset
    32
import jdk.internal.reflect.Reflection;
42707
6059f74bacdf 8171377: Add sun.misc.Unsafe::invokeCleaner
chegar
parents: 38774
diff changeset
    33
import sun.nio.ch.DirectBuffer;
16906
44dfee24cb71 8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents: 14853
diff changeset
    34
35253
ed92ce9fac46 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents: 33656
diff changeset
    35
import java.lang.reflect.Field;
ed92ce9fac46 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents: 33656
diff changeset
    36
import java.security.ProtectionDomain;
31671
362e0c0acece 8076112: Add @HotSpotIntrinsicCandidate annotation to indicate methods for which Java Runtime has intrinsics
zmajo
parents: 30655
diff changeset
    37
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * A collection of methods for performing low-level, unsafe operations.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * Although the class and all methods are public, use of this class is
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * limited because only trusted code can obtain instances of it.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 *
36628
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
    44
 * <em>Note:</em> It is the resposibility of the caller to make sure
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
    45
 * arguments are checked before methods of this class are
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
    46
 * called. While some rudimentary checks are performed on the input,
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
    47
 * the checks are best effort and when performance is an overriding
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
    48
 * priority, as when methods of this class are optimized by the
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
    49
 * runtime compiler, some or all checks (if any) may be elided. Hence,
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
    50
 * the caller must not rely on the checks and corresponding
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
    51
 * exceptions!
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
    52
 *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 * @author John R. Rose
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 * @see #getUnsafe
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
public final class Unsafe {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
    static {
37363
329dba26ffd2 8137058: Clear out all non-Critical APIs from sun.reflect
chegar
parents: 36966
diff changeset
    60
        Reflection.registerMethodsToFilter(Unsafe.class, "getUnsafe");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
    private Unsafe() {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
    private static final Unsafe theUnsafe = new Unsafe();
36628
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
    66
    private static final jdk.internal.misc.Unsafe theInternalUnsafe = jdk.internal.misc.Unsafe.getUnsafe();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
     * Provides the caller with the capability of performing unsafe
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
     * operations.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
     *
29388
c821b03af80a 8074577: Modernize Unsafe internal javadoc
martin
parents: 29028
diff changeset
    72
     * <p>The returned {@code Unsafe} object should be carefully guarded
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
     * by the caller, since it can be used to read and write data at arbitrary
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
     * memory addresses.  It must never be passed to untrusted code.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
     *
29388
c821b03af80a 8074577: Modernize Unsafe internal javadoc
martin
parents: 29028
diff changeset
    76
     * <p>Most methods in this class are very low-level, and correspond to a
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
     * small number of hardware instructions (on typical machines).  Compilers
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
     * are encouraged to optimize these methods accordingly.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
     *
29388
c821b03af80a 8074577: Modernize Unsafe internal javadoc
martin
parents: 29028
diff changeset
    80
     * <p>Here is a suggested idiom for using unsafe operations:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
     *
29388
c821b03af80a 8074577: Modernize Unsafe internal javadoc
martin
parents: 29028
diff changeset
    82
     * <pre> {@code
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
     * class MyTrustedClass {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
     *   private static final Unsafe unsafe = Unsafe.getUnsafe();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
     *   ...
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
     *   private long myCountAddress = ...;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
     *   public int getCount() { return unsafe.getByte(myCountAddress); }
29388
c821b03af80a 8074577: Modernize Unsafe internal javadoc
martin
parents: 29028
diff changeset
    88
     * }}</pre>
c821b03af80a 8074577: Modernize Unsafe internal javadoc
martin
parents: 29028
diff changeset
    89
     *
c821b03af80a 8074577: Modernize Unsafe internal javadoc
martin
parents: 29028
diff changeset
    90
     * (It may assist compilers to make the local variable {@code final}.)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
     *
38774
b2ca0c2ec115 8156868: MethodHandles.zero(Class) doc issues
mhaupt
parents: 38562
diff changeset
    92
     * @throws  SecurityException if the class loader of the caller
b2ca0c2ec115 8156868: MethodHandles.zero(Class) doc issues
mhaupt
parents: 38562
diff changeset
    93
     *          class is not in the system domain in which all permissions
b2ca0c2ec115 8156868: MethodHandles.zero(Class) doc issues
mhaupt
parents: 38562
diff changeset
    94
     *          are granted.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
     */
16906
44dfee24cb71 8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents: 14853
diff changeset
    96
    @CallerSensitive
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
    public static Unsafe getUnsafe() {
16906
44dfee24cb71 8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents: 14853
diff changeset
    98
        Class<?> caller = Reflection.getCallerClass();
44dfee24cb71 8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents: 14853
diff changeset
    99
        if (!VM.isSystemDomainLoader(caller.getClassLoader()))
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
            throw new SecurityException("Unsafe");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
        return theUnsafe;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
    /// peek and poke operations
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
    /// (compilers should optimize these to memory ops)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
    // These work on object fields in the Java heap.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
    // They will not work on elements of packed arrays.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
     * Fetches a value from a given Java variable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
     * More specifically, fetches a field or array element within the given
29388
c821b03af80a 8074577: Modernize Unsafe internal javadoc
martin
parents: 29028
diff changeset
   113
     * object {@code o} at the given offset, or (if {@code o} is null)
c821b03af80a 8074577: Modernize Unsafe internal javadoc
martin
parents: 29028
diff changeset
   114
     * from the memory address whose numerical value is the given offset.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
     * The results are undefined unless one of the following cases is true:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
     * <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
     * <li>The offset was obtained from {@link #objectFieldOffset} on
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
     * the {@link java.lang.reflect.Field} of some Java field and the object
29388
c821b03af80a 8074577: Modernize Unsafe internal javadoc
martin
parents: 29028
diff changeset
   120
     * referred to by {@code o} is of a class compatible with that
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
     * field's class.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
     *
29388
c821b03af80a 8074577: Modernize Unsafe internal javadoc
martin
parents: 29028
diff changeset
   123
     * <li>The offset and object reference {@code o} (either null or
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
     * non-null) were both obtained via {@link #staticFieldOffset}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
     * and {@link #staticFieldBase} (respectively) from the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
     * reflective {@link Field} representation of some Java field.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
     *
29388
c821b03af80a 8074577: Modernize Unsafe internal javadoc
martin
parents: 29028
diff changeset
   128
     * <li>The object referred to by {@code o} is an array, and the offset
c821b03af80a 8074577: Modernize Unsafe internal javadoc
martin
parents: 29028
diff changeset
   129
     * is an integer of the form {@code B+N*S}, where {@code N} is
c821b03af80a 8074577: Modernize Unsafe internal javadoc
martin
parents: 29028
diff changeset
   130
     * a valid index into the array, and {@code B} and {@code S} are
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
     * the values obtained by {@link #arrayBaseOffset} and {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
     * #arrayIndexScale} (respectively) from the array's class.  The value
29388
c821b03af80a 8074577: Modernize Unsafe internal javadoc
martin
parents: 29028
diff changeset
   133
     * referred to is the {@code N}<em>th</em> element of the array.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
     * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
     * If one of the above cases is true, the call references a specific Java
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
     * variable (field or array element).  However, the results are undefined
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
     * if that variable is not in fact of the type returned by this method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
     * This method refers to a variable by means of two parameters, and so
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
     * it provides (in effect) a <em>double-register</em> addressing mode
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
     * for Java variables.  When the object reference is null, this method
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
     * uses its offset as an absolute address.  This is similar in operation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
     * to methods such as {@link #getInt(long)}, which provide (in effect) a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
     * <em>single-register</em> addressing mode for non-Java variables.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
     * However, because Java variables may have a different layout in memory
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
     * from non-Java variables, programmers should not assume that these
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
     * two addressing modes are ever equivalent.  Also, programmers should
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
     * remember that offsets from the double-register addressing mode cannot
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
     * be portably confused with longs used in the single-register addressing
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
     * mode.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
     * @param o Java heap object in which the variable resides, if any, else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
     *        null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
     * @param offset indication of where the variable resides in a Java heap
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
     *        object, if any, else a memory address locating the variable
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
     *        statically
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
     * @return the value fetched from the indicated Java variable
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
     * @throws RuntimeException No defined exceptions are thrown, not even
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
     *         {@link NullPointerException}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
     */
36628
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   163
    @ForceInline
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   164
    public int getInt(Object o, long offset) {
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   165
        return theInternalUnsafe.getInt(o, offset);
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   166
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
     * Stores a value into a given Java variable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
     * The first two parameters are interpreted exactly as with
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
     * {@link #getInt(Object, long)} to refer to a specific
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
     * Java variable (field or array element).  The given value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
     * is stored into that variable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
     * The variable must be of the same type as the method
29388
c821b03af80a 8074577: Modernize Unsafe internal javadoc
martin
parents: 29028
diff changeset
   177
     * parameter {@code x}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
     * @param o Java heap object in which the variable resides, if any, else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
     *        null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
     * @param offset indication of where the variable resides in a Java heap
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
     *        object, if any, else a memory address locating the variable
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
     *        statically
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
     * @param x the value to store into the indicated Java variable
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
     * @throws RuntimeException No defined exceptions are thrown, not even
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
     *         {@link NullPointerException}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
     */
36628
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   188
    @ForceInline
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   189
    public void putInt(Object o, long offset, int x) {
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   190
        theInternalUnsafe.putInt(o, offset, x);
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   191
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
     * Fetches a reference value from a given Java variable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
     * @see #getInt(Object, long)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
     */
36628
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   197
    @ForceInline
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   198
    public Object getObject(Object o, long offset) {
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   199
        return theInternalUnsafe.getObject(o, offset);
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   200
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
     * Stores a reference value into a given Java variable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
     * <p>
29388
c821b03af80a 8074577: Modernize Unsafe internal javadoc
martin
parents: 29028
diff changeset
   205
     * Unless the reference {@code x} being stored is either null
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
     * or matches the field type, the results are undefined.
30361
76bb3472a9dd 8022853: add ability to load uncompressed object and Klass references in a compressed environment to Unsafe
twisti
parents: 30338
diff changeset
   207
     * If the reference {@code o} is non-null, card marks or
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
     * other store barriers for that object (if the VM requires them)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
     * are updated.
29028
f97d41a21983 8068975: Remove deprecated methods on sun.misc.Unsafe and clean up native implementation
psandoz
parents: 28671
diff changeset
   210
     * @see #putInt(Object, long, int)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
     */
36628
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   212
    @ForceInline
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   213
    public void putObject(Object o, long offset, Object x) {
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   214
        theInternalUnsafe.putObject(o, offset, x);
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   215
    }
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   216
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   217
    /** @see #getInt(Object, long) */
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   218
    @ForceInline
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   219
    public boolean getBoolean(Object o, long offset) {
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   220
        return theInternalUnsafe.getBoolean(o, offset);
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   221
    }
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   222
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   223
    /** @see #putInt(Object, long, int) */
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   224
    @ForceInline
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   225
    public void putBoolean(Object o, long offset, boolean x) {
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   226
        theInternalUnsafe.putBoolean(o, offset, x);
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   227
    }
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   228
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   229
    /** @see #getInt(Object, long) */
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   230
    @ForceInline
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   231
    public byte getByte(Object o, long offset) {
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   232
        return theInternalUnsafe.getByte(o, offset);
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   233
    }
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   234
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   235
    /** @see #putInt(Object, long, int) */
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   236
    @ForceInline
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   237
    public void putByte(Object o, long offset, byte x) {
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   238
        theInternalUnsafe.putByte(o, offset, x);
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   239
    }
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   240
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   241
    /** @see #getInt(Object, long) */
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   242
    @ForceInline
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   243
    public short getShort(Object o, long offset) {
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   244
        return theInternalUnsafe.getShort(o, offset);
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   245
    }
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   246
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   247
    /** @see #putInt(Object, long, int) */
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   248
    @ForceInline
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   249
    public void putShort(Object o, long offset, short x) {
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   250
        theInternalUnsafe.putShort(o, offset, x);
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   251
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
    /** @see #getInt(Object, long) */
36628
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   254
    @ForceInline
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   255
    public char getChar(Object o, long offset) {
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   256
        return theInternalUnsafe.getChar(o, offset);
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   257
    }
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   258
29028
f97d41a21983 8068975: Remove deprecated methods on sun.misc.Unsafe and clean up native implementation
psandoz
parents: 28671
diff changeset
   259
    /** @see #putInt(Object, long, int) */
36628
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   260
    @ForceInline
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   261
    public void putChar(Object o, long offset, char x) {
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   262
        theInternalUnsafe.putChar(o, offset, x);
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   263
    }
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   264
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
    /** @see #getInt(Object, long) */
36628
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   266
    @ForceInline
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   267
    public long getLong(Object o, long offset) {
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   268
        return theInternalUnsafe.getLong(o, offset);
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   269
    }
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   270
29028
f97d41a21983 8068975: Remove deprecated methods on sun.misc.Unsafe and clean up native implementation
psandoz
parents: 28671
diff changeset
   271
    /** @see #putInt(Object, long, int) */
36628
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   272
    @ForceInline
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   273
    public void putLong(Object o, long offset, long x) {
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   274
        theInternalUnsafe.putLong(o, offset, x);
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   275
    }
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   276
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
    /** @see #getInt(Object, long) */
36628
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   278
    @ForceInline
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   279
    public float getFloat(Object o, long offset) {
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   280
        return theInternalUnsafe.getFloat(o, offset);
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   281
    }
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   282
29028
f97d41a21983 8068975: Remove deprecated methods on sun.misc.Unsafe and clean up native implementation
psandoz
parents: 28671
diff changeset
   283
    /** @see #putInt(Object, long, int) */
36628
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   284
    @ForceInline
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   285
    public void putFloat(Object o, long offset, float x) {
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   286
        theInternalUnsafe.putFloat(o, offset, x);
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   287
    }
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   288
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
    /** @see #getInt(Object, long) */
36628
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   290
    @ForceInline
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   291
    public double getDouble(Object o, long offset) {
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   292
        return theInternalUnsafe.getDouble(o, offset);
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   293
    }
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   294
29028
f97d41a21983 8068975: Remove deprecated methods on sun.misc.Unsafe and clean up native implementation
psandoz
parents: 28671
diff changeset
   295
    /** @see #putInt(Object, long, int) */
36628
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   296
    @ForceInline
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   297
    public void putDouble(Object o, long offset, double x) {
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   298
        theInternalUnsafe.putDouble(o, offset, x);
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   299
    }
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   300
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
    // These work on values in the C heap.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
     * Fetches a value from a given memory address.  If the address is zero, or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
     * does not point into a block obtained from {@link #allocateMemory}, the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
     * results are undefined.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
     * @see #allocateMemory
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
     */
36628
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   310
    @ForceInline
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   311
    public byte getByte(long address) {
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   312
        return theInternalUnsafe.getByte(address);
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   313
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
     * Stores a value into a given memory address.  If the address is zero, or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
     * does not point into a block obtained from {@link #allocateMemory}, the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
     * results are undefined.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
     * @see #getByte(long)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
     */
36628
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   322
    @ForceInline
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   323
    public void putByte(long address, byte x) {
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   324
        theInternalUnsafe.putByte(address, x);
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   325
    }
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   326
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   327
    /** @see #getByte(long) */
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   328
    @ForceInline
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   329
    public short getShort(long address) {
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   330
        return theInternalUnsafe.getShort(address);
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   331
    }
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   332
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   333
    /** @see #putByte(long, byte) */
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   334
    @ForceInline
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   335
    public void putShort(long address, short x) {
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   336
        theInternalUnsafe.putShort(address, x);
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   337
    }
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   338
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   339
    /** @see #getByte(long) */
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   340
    @ForceInline
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   341
    public char getChar(long address) {
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   342
        return theInternalUnsafe.getChar(address);
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   343
    }
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   344
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   345
    /** @see #putByte(long, byte) */
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   346
    @ForceInline
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   347
    public void putChar(long address, char x) {
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   348
        theInternalUnsafe.putChar(address, x);
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   349
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
    /** @see #getByte(long) */
36628
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   352
    @ForceInline
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   353
    public int getInt(long address) {
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   354
        return theInternalUnsafe.getInt(address);
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   355
    }
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   356
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
    /** @see #putByte(long, byte) */
36628
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   358
    @ForceInline
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   359
    public void putInt(long address, int x) {
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   360
        theInternalUnsafe.putInt(address, x);
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   361
    }
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   362
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
    /** @see #getByte(long) */
36628
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   364
    @ForceInline
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   365
    public long getLong(long address) {
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   366
        return theInternalUnsafe.getLong(address);
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   367
    }
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   368
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
    /** @see #putByte(long, byte) */
36628
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   370
    @ForceInline
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   371
    public void putLong(long address, long x) {
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   372
        theInternalUnsafe.putLong(address, x);
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   373
    }
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   374
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
    /** @see #getByte(long) */
36628
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   376
    @ForceInline
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   377
    public float getFloat(long address) {
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   378
        return theInternalUnsafe.getFloat(address);
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   379
    }
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   380
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
    /** @see #putByte(long, byte) */
36628
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   382
    @ForceInline
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   383
    public void putFloat(long address, float x) {
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   384
        theInternalUnsafe.putFloat(address, x);
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   385
    }
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   386
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
    /** @see #getByte(long) */
36628
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   388
    @ForceInline
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   389
    public double getDouble(long address) {
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   390
        return theInternalUnsafe.getDouble(address);
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   391
    }
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   392
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
    /** @see #putByte(long, byte) */
36628
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   394
    @ForceInline
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   395
    public void putDouble(long address, double x) {
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   396
        theInternalUnsafe.putDouble(address, x);
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   397
    }
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   398
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
     * Fetches a native pointer from a given memory address.  If the address is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
     * zero, or does not point into a block obtained from {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
     * #allocateMemory}, the results are undefined.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
     *
29388
c821b03af80a 8074577: Modernize Unsafe internal javadoc
martin
parents: 29028
diff changeset
   405
     * <p>If the native pointer is less than 64 bits wide, it is extended as
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
     * an unsigned number to a Java long.  The pointer may be indexed by any
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
     * given byte offset, simply by adding that offset (as a simple integer) to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
     * the long representing the pointer.  The number of bytes actually read
29388
c821b03af80a 8074577: Modernize Unsafe internal javadoc
martin
parents: 29028
diff changeset
   409
     * from the target address may be determined by consulting {@link
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
     * #addressSize}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
     * @see #allocateMemory
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
     */
36628
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   414
    @ForceInline
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   415
    public long getAddress(long address) {
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   416
        return theInternalUnsafe.getAddress(address);
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   417
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
     * Stores a native pointer into a given memory address.  If the address is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
     * zero, or does not point into a block obtained from {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
     * #allocateMemory}, the results are undefined.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
     *
29388
c821b03af80a 8074577: Modernize Unsafe internal javadoc
martin
parents: 29028
diff changeset
   424
     * <p>The number of bytes actually written at the target address may be
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
     * determined by consulting {@link #addressSize}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
     * @see #getAddress(long)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
     */
36628
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   429
    @ForceInline
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   430
    public void putAddress(long address, long x) {
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   431
        theInternalUnsafe.putAddress(address, x);
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   432
    }
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   433
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
    /// wrappers for malloc, realloc, free:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
     * Allocates a new block of native memory, of the given size in bytes.  The
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
     * contents of the memory are uninitialized; they will generally be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
     * garbage.  The resulting native pointer will never be zero, and will be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
     * aligned for all value types.  Dispose of this memory by calling {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
     * #freeMemory}, or resize it with {@link #reallocateMemory}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
     *
36628
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   444
     * <em>Note:</em> It is the resposibility of the caller to make
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   445
     * sure arguments are checked before the methods are called. While
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   446
     * some rudimentary checks are performed on the input, the checks
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   447
     * are best effort and when performance is an overriding priority,
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   448
     * as when methods of this class are optimized by the runtime
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   449
     * compiler, some or all checks (if any) may be elided. Hence, the
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   450
     * caller must not rely on the checks and corresponding
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   451
     * exceptions!
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   452
     *
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   453
     * @throws RuntimeException if the size is negative or too large
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
     *         for the native size_t type
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
     * @throws OutOfMemoryError if the allocation is refused by the system
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
     * @see #getByte(long)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
     * @see #putByte(long, byte)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
     */
36628
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   461
    @ForceInline
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   462
    public long allocateMemory(long bytes) {
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   463
        return theInternalUnsafe.allocateMemory(bytes);
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   464
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
     * Resizes a new block of native memory, to the given size in bytes.  The
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
     * contents of the new block past the size of the old block are
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
     * uninitialized; they will generally be garbage.  The resulting native
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
     * pointer will be zero if and only if the requested size is zero.  The
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
     * resulting native pointer will be aligned for all value types.  Dispose
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
     * of this memory by calling {@link #freeMemory}, or resize it with {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
     * #reallocateMemory}.  The address passed to this method may be null, in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
     * which case an allocation will be performed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
     *
36628
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   476
     * <em>Note:</em> It is the resposibility of the caller to make
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   477
     * sure arguments are checked before the methods are called. While
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   478
     * some rudimentary checks are performed on the input, the checks
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   479
     * are best effort and when performance is an overriding priority,
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   480
     * as when methods of this class are optimized by the runtime
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   481
     * compiler, some or all checks (if any) may be elided. Hence, the
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   482
     * caller must not rely on the checks and corresponding
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   483
     * exceptions!
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   484
     *
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   485
     * @throws RuntimeException if the size is negative or too large
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
     *         for the native size_t type
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
     * @throws OutOfMemoryError if the allocation is refused by the system
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
     * @see #allocateMemory
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
     */
36628
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   492
    @ForceInline
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   493
    public long reallocateMemory(long address, long bytes) {
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   494
        return theInternalUnsafe.reallocateMemory(address, bytes);
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   495
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
     * Sets all bytes in a given block of memory to a fixed value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
     * (usually zero).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
     * <p>This method determines a block's base address by means of two parameters,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
     * and so it provides (in effect) a <em>double-register</em> addressing mode,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
     * as discussed in {@link #getInt(Object,long)}.  When the object reference is null,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
     * the offset supplies an absolute base address.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
     * <p>The stores are in coherent (atomic) units of a size determined
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
     * by the address and length parameters.  If the effective address and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
     * length are all even modulo 8, the stores take place in 'long' units.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
     * If the effective address and length are (resp.) even modulo 4 or 2,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
     * the stores take place in units of 'int' or 'short'.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
     *
36628
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   512
     * <em>Note:</em> It is the resposibility of the caller to make
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   513
     * sure arguments are checked before the methods are called. While
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   514
     * some rudimentary checks are performed on the input, the checks
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   515
     * are best effort and when performance is an overriding priority,
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   516
     * as when methods of this class are optimized by the runtime
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   517
     * compiler, some or all checks (if any) may be elided. Hence, the
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   518
     * caller must not rely on the checks and corresponding
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   519
     * exceptions!
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   520
     *
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   521
     * @throws RuntimeException if any of the arguments is invalid
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   522
     *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
     * @since 1.7
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
     */
36628
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   525
    @ForceInline
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   526
    public void setMemory(Object o, long offset, long bytes, byte value) {
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   527
        theInternalUnsafe.setMemory(o, offset, bytes, value);
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   528
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
     * Sets all bytes in a given block of memory to a fixed value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
     * (usually zero).  This provides a <em>single-register</em> addressing mode,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
     * as discussed in {@link #getInt(Object,long)}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
     *
29388
c821b03af80a 8074577: Modernize Unsafe internal javadoc
martin
parents: 29028
diff changeset
   535
     * <p>Equivalent to {@code setMemory(null, address, bytes, value)}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
     */
36628
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   537
    @ForceInline
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
    public void setMemory(long address, long bytes, byte value) {
36628
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   539
        theInternalUnsafe.setMemory(address, bytes, value);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
     * Sets all bytes in a given block of memory to a copy of another
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
     * block.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
     * <p>This method determines each block's base address by means of two parameters,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
     * and so it provides (in effect) a <em>double-register</em> addressing mode,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
     * as discussed in {@link #getInt(Object,long)}.  When the object reference is null,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
     * the offset supplies an absolute base address.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
     * <p>The transfers are in coherent (atomic) units of a size determined
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
     * by the address and length parameters.  If the effective addresses and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
     * length are all even modulo 8, the transfer takes place in 'long' units.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
     * If the effective addresses and length are (resp.) even modulo 4 or 2,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
     * the transfer takes place in units of 'int' or 'short'.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
     *
36628
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   557
     * <em>Note:</em> It is the resposibility of the caller to make
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   558
     * sure arguments are checked before the methods are called. While
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   559
     * some rudimentary checks are performed on the input, the checks
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   560
     * are best effort and when performance is an overriding priority,
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   561
     * as when methods of this class are optimized by the runtime
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   562
     * compiler, some or all checks (if any) may be elided. Hence, the
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   563
     * caller must not rely on the checks and corresponding
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   564
     * exceptions!
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   565
     *
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   566
     * @throws RuntimeException if any of the arguments is invalid
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   567
     *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
     * @since 1.7
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
     */
36628
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   570
    @ForceInline
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   571
    public void copyMemory(Object srcBase, long srcOffset,
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   572
                           Object destBase, long destOffset,
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   573
                           long bytes) {
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   574
        theInternalUnsafe.copyMemory(srcBase, srcOffset, destBase, destOffset, bytes);
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   575
    }
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   576
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
     * Sets all bytes in a given block of memory to a copy of another
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
     * block.  This provides a <em>single-register</em> addressing mode,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
     * as discussed in {@link #getInt(Object,long)}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
     *
29388
c821b03af80a 8074577: Modernize Unsafe internal javadoc
martin
parents: 29028
diff changeset
   582
     * Equivalent to {@code copyMemory(null, srcAddress, null, destAddress, bytes)}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
     */
36628
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   584
    @ForceInline
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
    public void copyMemory(long srcAddress, long destAddress, long bytes) {
36628
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   586
        theInternalUnsafe.copyMemory(srcAddress, destAddress, bytes);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
     * Disposes of a block of native memory, as obtained from {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
     * #allocateMemory} or {@link #reallocateMemory}.  The address passed to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
     * this method may be null, in which case no action is taken.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
     *
36628
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   594
     * <em>Note:</em> It is the resposibility of the caller to make
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   595
     * sure arguments are checked before the methods are called. While
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   596
     * some rudimentary checks are performed on the input, the checks
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   597
     * are best effort and when performance is an overriding priority,
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   598
     * as when methods of this class are optimized by the runtime
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   599
     * compiler, some or all checks (if any) may be elided. Hence, the
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   600
     * caller must not rely on the checks and corresponding
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   601
     * exceptions!
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   602
     *
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   603
     * @throws RuntimeException if any of the arguments is invalid
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   604
     *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
     * @see #allocateMemory
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
     */
36628
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   607
    @ForceInline
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   608
    public void freeMemory(long address) {
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   609
        theInternalUnsafe.freeMemory(address);
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   610
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
    /// random queries
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
     * This constant differs from all results that will ever be returned from
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
     * {@link #staticFieldOffset}, {@link #objectFieldOffset},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
     * or {@link #arrayBaseOffset}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
     */
36628
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   619
    public static final int INVALID_FIELD_OFFSET = jdk.internal.misc.Unsafe.INVALID_FIELD_OFFSET;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
    /**
29388
c821b03af80a 8074577: Modernize Unsafe internal javadoc
martin
parents: 29028
diff changeset
   622
     * Reports the location of a given field in the storage allocation of its
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
     * class.  Do not expect to perform any sort of arithmetic on this offset;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
     * it is just a cookie which is passed to the unsafe heap memory accessors.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
     * <p>Any given field will always have the same offset and base, and no
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
     * two distinct fields of the same class will ever have the same offset
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
     * and base.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
     * <p>As of 1.4.1, offsets for fields are represented as long values,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
     * although the Sun JVM does not use the most significant 32 bits.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
     * However, JVM implementations which store static fields at absolute
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
     * addresses can use long offsets and null base pointers to express
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
     * the field locations in a form usable by {@link #getInt(Object,long)}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
     * Therefore, code which will be ported to such JVMs on 64-bit platforms
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
     * must preserve all bits of static field offsets.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
     * @see #getInt(Object, long)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
     */
36628
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   639
    @ForceInline
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   640
    public long objectFieldOffset(Field f) {
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   641
        return theInternalUnsafe.objectFieldOffset(f);
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   642
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
    /**
29388
c821b03af80a 8074577: Modernize Unsafe internal javadoc
martin
parents: 29028
diff changeset
   645
     * Reports the location of a given static field, in conjunction with {@link
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
     * #staticFieldBase}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
     * <p>Do not expect to perform any sort of arithmetic on this offset;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
     * it is just a cookie which is passed to the unsafe heap memory accessors.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
     * <p>Any given field will always have the same offset, and no two distinct
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
     * fields of the same class will ever have the same offset.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
     * <p>As of 1.4.1, offsets for fields are represented as long values,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
     * although the Sun JVM does not use the most significant 32 bits.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
     * It is hard to imagine a JVM technology which needs more than
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
     * a few bits to encode an offset within a non-array object,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
     * However, for consistency with other methods in this class,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
     * this method reports its result as a long value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
     * @see #getInt(Object, long)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
     */
36628
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   661
    @ForceInline
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   662
    public long staticFieldOffset(Field f) {
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   663
        return theInternalUnsafe.staticFieldOffset(f);
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   664
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
    /**
29388
c821b03af80a 8074577: Modernize Unsafe internal javadoc
martin
parents: 29028
diff changeset
   667
     * Reports the location of a given static field, in conjunction with {@link
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
     * #staticFieldOffset}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
     * <p>Fetch the base "Object", if any, with which static fields of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
     * given class can be accessed via methods like {@link #getInt(Object,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
     * long)}.  This value may be null.  This value may refer to an object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
     * which is a "cookie", not guaranteed to be a real Object, and it should
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
     * not be used in any way except as argument to the get and put routines in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
     * this class.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
     */
36628
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   676
    @ForceInline
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   677
    public Object staticFieldBase(Field f) {
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   678
        return theInternalUnsafe.staticFieldBase(f);
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   679
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
    /**
29388
c821b03af80a 8074577: Modernize Unsafe internal javadoc
martin
parents: 29028
diff changeset
   682
     * Detects if the given class may need to be initialized. This is often
13423
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 11117
diff changeset
   683
     * needed in conjunction with obtaining the static field base of a
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 11117
diff changeset
   684
     * class.
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 11117
diff changeset
   685
     * @return false only if a call to {@code ensureClassInitialized} would have no effect
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 11117
diff changeset
   686
     */
36628
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   687
    @ForceInline
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   688
    public boolean shouldBeInitialized(Class<?> c) {
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   689
        return theInternalUnsafe.shouldBeInitialized(c);
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   690
    }
13423
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 11117
diff changeset
   691
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 11117
diff changeset
   692
    /**
29388
c821b03af80a 8074577: Modernize Unsafe internal javadoc
martin
parents: 29028
diff changeset
   693
     * Ensures the given class has been initialized. This is often
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
     * needed in conjunction with obtaining the static field base of a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
     * class.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
     */
36628
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   697
    @ForceInline
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   698
    public void ensureClassInitialized(Class<?> c) {
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   699
        theInternalUnsafe.ensureClassInitialized(c);
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   700
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
    /**
29388
c821b03af80a 8074577: Modernize Unsafe internal javadoc
martin
parents: 29028
diff changeset
   703
     * Reports the offset of the first element in the storage allocation of a
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
     * given array class.  If {@link #arrayIndexScale} returns a non-zero value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
     * for the same class, you may use that scale factor, together with this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
     * base offset, to form new offsets to access elements of arrays of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
     * given class.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
     * @see #getInt(Object, long)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
     * @see #putInt(Object, long, int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
     */
36628
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   712
    @ForceInline
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   713
    public int arrayBaseOffset(Class<?> arrayClass) {
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   714
        return theInternalUnsafe.arrayBaseOffset(arrayClass);
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   715
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
    /** The value of {@code arrayBaseOffset(boolean[].class)} */
36628
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   718
    public static final int ARRAY_BOOLEAN_BASE_OFFSET = jdk.internal.misc.Unsafe.ARRAY_BOOLEAN_BASE_OFFSET;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
    /** The value of {@code arrayBaseOffset(byte[].class)} */
36628
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   721
    public static final int ARRAY_BYTE_BASE_OFFSET = jdk.internal.misc.Unsafe.ARRAY_BYTE_BASE_OFFSET;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   722
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
    /** The value of {@code arrayBaseOffset(short[].class)} */
36628
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   724
    public static final int ARRAY_SHORT_BASE_OFFSET = jdk.internal.misc.Unsafe.ARRAY_SHORT_BASE_OFFSET;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   725
90ce3da70b43 Initial load
duke
parents:
diff changeset
   726
    /** The value of {@code arrayBaseOffset(char[].class)} */
36628
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   727
    public static final int ARRAY_CHAR_BASE_OFFSET = jdk.internal.misc.Unsafe.ARRAY_CHAR_BASE_OFFSET;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   728
90ce3da70b43 Initial load
duke
parents:
diff changeset
   729
    /** The value of {@code arrayBaseOffset(int[].class)} */
36628
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   730
    public static final int ARRAY_INT_BASE_OFFSET = jdk.internal.misc.Unsafe.ARRAY_INT_BASE_OFFSET;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   731
90ce3da70b43 Initial load
duke
parents:
diff changeset
   732
    /** The value of {@code arrayBaseOffset(long[].class)} */
36628
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   733
    public static final int ARRAY_LONG_BASE_OFFSET = jdk.internal.misc.Unsafe.ARRAY_LONG_BASE_OFFSET;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   734
90ce3da70b43 Initial load
duke
parents:
diff changeset
   735
    /** The value of {@code arrayBaseOffset(float[].class)} */
36628
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   736
    public static final int ARRAY_FLOAT_BASE_OFFSET = jdk.internal.misc.Unsafe.ARRAY_FLOAT_BASE_OFFSET;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   737
90ce3da70b43 Initial load
duke
parents:
diff changeset
   738
    /** The value of {@code arrayBaseOffset(double[].class)} */
36628
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   739
    public static final int ARRAY_DOUBLE_BASE_OFFSET = jdk.internal.misc.Unsafe.ARRAY_DOUBLE_BASE_OFFSET;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   740
90ce3da70b43 Initial load
duke
parents:
diff changeset
   741
    /** The value of {@code arrayBaseOffset(Object[].class)} */
36628
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   742
    public static final int ARRAY_OBJECT_BASE_OFFSET = jdk.internal.misc.Unsafe.ARRAY_OBJECT_BASE_OFFSET;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   743
90ce3da70b43 Initial load
duke
parents:
diff changeset
   744
    /**
29388
c821b03af80a 8074577: Modernize Unsafe internal javadoc
martin
parents: 29028
diff changeset
   745
     * Reports the scale factor for addressing elements in the storage
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   746
     * allocation of a given array class.  However, arrays of "narrow" types
90ce3da70b43 Initial load
duke
parents:
diff changeset
   747
     * will generally not work properly with accessors like {@link
29028
f97d41a21983 8068975: Remove deprecated methods on sun.misc.Unsafe and clean up native implementation
psandoz
parents: 28671
diff changeset
   748
     * #getByte(Object, long)}, so the scale factor for such classes is reported
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   749
     * as zero.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   750
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   751
     * @see #arrayBaseOffset
90ce3da70b43 Initial load
duke
parents:
diff changeset
   752
     * @see #getInt(Object, long)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   753
     * @see #putInt(Object, long, int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   754
     */
36628
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   755
    @ForceInline
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   756
    public int arrayIndexScale(Class<?> arrayClass) {
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   757
        return theInternalUnsafe.arrayIndexScale(arrayClass);
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   758
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   759
90ce3da70b43 Initial load
duke
parents:
diff changeset
   760
    /** The value of {@code arrayIndexScale(boolean[].class)} */
36628
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   761
    public static final int ARRAY_BOOLEAN_INDEX_SCALE = jdk.internal.misc.Unsafe.ARRAY_BOOLEAN_INDEX_SCALE;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   762
90ce3da70b43 Initial load
duke
parents:
diff changeset
   763
    /** The value of {@code arrayIndexScale(byte[].class)} */
36628
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   764
    public static final int ARRAY_BYTE_INDEX_SCALE = jdk.internal.misc.Unsafe.ARRAY_BYTE_INDEX_SCALE;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   765
90ce3da70b43 Initial load
duke
parents:
diff changeset
   766
    /** The value of {@code arrayIndexScale(short[].class)} */
36628
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   767
    public static final int ARRAY_SHORT_INDEX_SCALE = jdk.internal.misc.Unsafe.ARRAY_SHORT_INDEX_SCALE;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   768
90ce3da70b43 Initial load
duke
parents:
diff changeset
   769
    /** The value of {@code arrayIndexScale(char[].class)} */
36628
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   770
    public static final int ARRAY_CHAR_INDEX_SCALE = jdk.internal.misc.Unsafe.ARRAY_CHAR_INDEX_SCALE;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   771
90ce3da70b43 Initial load
duke
parents:
diff changeset
   772
    /** The value of {@code arrayIndexScale(int[].class)} */
36628
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   773
    public static final int ARRAY_INT_INDEX_SCALE = jdk.internal.misc.Unsafe.ARRAY_INT_INDEX_SCALE;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   774
90ce3da70b43 Initial load
duke
parents:
diff changeset
   775
    /** The value of {@code arrayIndexScale(long[].class)} */
36628
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   776
    public static final int ARRAY_LONG_INDEX_SCALE = jdk.internal.misc.Unsafe.ARRAY_LONG_INDEX_SCALE;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   777
90ce3da70b43 Initial load
duke
parents:
diff changeset
   778
    /** The value of {@code arrayIndexScale(float[].class)} */
36628
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   779
    public static final int ARRAY_FLOAT_INDEX_SCALE = jdk.internal.misc.Unsafe.ARRAY_FLOAT_INDEX_SCALE;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   780
90ce3da70b43 Initial load
duke
parents:
diff changeset
   781
    /** The value of {@code arrayIndexScale(double[].class)} */
36628
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   782
    public static final int ARRAY_DOUBLE_INDEX_SCALE = jdk.internal.misc.Unsafe.ARRAY_DOUBLE_INDEX_SCALE;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   783
90ce3da70b43 Initial load
duke
parents:
diff changeset
   784
    /** The value of {@code arrayIndexScale(Object[].class)} */
36628
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   785
    public static final int ARRAY_OBJECT_INDEX_SCALE = jdk.internal.misc.Unsafe.ARRAY_OBJECT_INDEX_SCALE;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   786
90ce3da70b43 Initial load
duke
parents:
diff changeset
   787
    /**
29388
c821b03af80a 8074577: Modernize Unsafe internal javadoc
martin
parents: 29028
diff changeset
   788
     * Reports the size in bytes of a native pointer, as stored via {@link
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   789
     * #putAddress}.  This value will be either 4 or 8.  Note that the sizes of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   790
     * other primitive types (as stored in native memory blocks) is determined
90ce3da70b43 Initial load
duke
parents:
diff changeset
   791
     * fully by their information content.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   792
     */
36628
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   793
    @ForceInline
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   794
    public int addressSize() {
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   795
        return theInternalUnsafe.addressSize();
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   796
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   797
90ce3da70b43 Initial load
duke
parents:
diff changeset
   798
    /** The value of {@code addressSize()} */
36628
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   799
    public static final int ADDRESS_SIZE = theInternalUnsafe.addressSize();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   800
90ce3da70b43 Initial load
duke
parents:
diff changeset
   801
    /**
29388
c821b03af80a 8074577: Modernize Unsafe internal javadoc
martin
parents: 29028
diff changeset
   802
     * Reports the size in bytes of a native memory page (whatever that is).
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   803
     * This value will always be a power of two.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   804
     */
36628
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   805
    @ForceInline
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   806
    public int pageSize() {
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   807
        return theInternalUnsafe.pageSize();
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   808
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   809
90ce3da70b43 Initial load
duke
parents:
diff changeset
   810
90ce3da70b43 Initial load
duke
parents:
diff changeset
   811
    /// random trusted operations from JNI:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   812
90ce3da70b43 Initial load
duke
parents:
diff changeset
   813
    /**
29388
c821b03af80a 8074577: Modernize Unsafe internal javadoc
martin
parents: 29028
diff changeset
   814
     * Tells the VM to define a class, without security checks.  By default, the
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   815
     * class loader and protection domain come from the caller's class.
45635
56b0672b0070 8181442: Deprecate sun.misc.Unsafe.defineClass
psandoz
parents: 45518
diff changeset
   816
     *
56b0672b0070 8181442: Deprecate sun.misc.Unsafe.defineClass
psandoz
parents: 45518
diff changeset
   817
     * @deprecated Use {@link java.lang.invoke.MethodHandles.Lookup#defineClass MethodHandles.Lookup#defineClass}
56b0672b0070 8181442: Deprecate sun.misc.Unsafe.defineClass
psandoz
parents: 45518
diff changeset
   818
     * to define a class to the same class loader and in the same runtime package
56b0672b0070 8181442: Deprecate sun.misc.Unsafe.defineClass
psandoz
parents: 45518
diff changeset
   819
     * and {@linkplain java.security.ProtectionDomain protection domain} of a
56b0672b0070 8181442: Deprecate sun.misc.Unsafe.defineClass
psandoz
parents: 45518
diff changeset
   820
     * given {@code Lookup}'s {@linkplain java.lang.invoke.MethodHandles.Lookup#lookupClass() lookup class}.
56b0672b0070 8181442: Deprecate sun.misc.Unsafe.defineClass
psandoz
parents: 45518
diff changeset
   821
     *
44359
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 42707
diff changeset
   822
     * @see java.lang.invoke.MethodHandles.Lookup#defineClass(byte[])
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   823
     */
45635
56b0672b0070 8181442: Deprecate sun.misc.Unsafe.defineClass
psandoz
parents: 45518
diff changeset
   824
    @Deprecated(since="9", forRemoval=true)
36628
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   825
    @ForceInline
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   826
    public Class<?> defineClass(String name, byte[] b, int off, int len,
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   827
                                ClassLoader loader,
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   828
                                ProtectionDomain protectionDomain) {
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   829
        return theInternalUnsafe.defineClass(name, b, off, len, loader, protectionDomain);
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   830
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   831
2707
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents: 2
diff changeset
   832
    /**
29388
c821b03af80a 8074577: Modernize Unsafe internal javadoc
martin
parents: 29028
diff changeset
   833
     * Defines a class but does not make it known to the class loader or system dictionary.
2707
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents: 2
diff changeset
   834
     * <p>
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents: 2
diff changeset
   835
     * For each CP entry, the corresponding CP patch must either be null or have
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents: 2
diff changeset
   836
     * the a format that matches its tag:
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents: 2
diff changeset
   837
     * <ul>
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents: 2
diff changeset
   838
     * <li>Integer, Long, Float, Double: the corresponding wrapper object type from java.lang
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents: 2
diff changeset
   839
     * <li>Utf8: a string (must have suitable syntax if used as signature or name)
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents: 2
diff changeset
   840
     * <li>Class: any java.lang.Class object
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents: 2
diff changeset
   841
     * <li>String: any object (not just a java.lang.String)
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents: 2
diff changeset
   842
     * <li>InterfaceMethodRef: (NYI) a method handle to invoke on that call site's arguments
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents: 2
diff changeset
   843
     * </ul>
30655
d83f50188ca9 8080422: some docs cleanup for core libs
avstepan
parents: 30361
diff changeset
   844
     * @param hostClass context for linkage, access control, protection domain, and class loader
d83f50188ca9 8080422: some docs cleanup for core libs
avstepan
parents: 30361
diff changeset
   845
     * @param data      bytes of a class file
d83f50188ca9 8080422: some docs cleanup for core libs
avstepan
parents: 30361
diff changeset
   846
     * @param cpPatches where non-null entries exist, they replace corresponding CP entries in data
2707
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents: 2
diff changeset
   847
     */
36628
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   848
    @ForceInline
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   849
    public Class<?> defineAnonymousClass(Class<?> hostClass, byte[] data, Object[] cpPatches) {
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   850
        return theInternalUnsafe.defineAnonymousClass(hostClass, data, cpPatches);
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   851
    }
2707
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents: 2
diff changeset
   852
29388
c821b03af80a 8074577: Modernize Unsafe internal javadoc
martin
parents: 29028
diff changeset
   853
    /**
c821b03af80a 8074577: Modernize Unsafe internal javadoc
martin
parents: 29028
diff changeset
   854
     * Allocates an instance but does not run any constructor.
c821b03af80a 8074577: Modernize Unsafe internal javadoc
martin
parents: 29028
diff changeset
   855
     * Initializes the class if it has not yet been.
c821b03af80a 8074577: Modernize Unsafe internal javadoc
martin
parents: 29028
diff changeset
   856
     */
36628
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   857
    @ForceInline
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   858
    public Object allocateInstance(Class<?> cls)
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   859
        throws InstantiationException {
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   860
        return theInternalUnsafe.allocateInstance(cls);
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   861
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   862
29388
c821b03af80a 8074577: Modernize Unsafe internal javadoc
martin
parents: 29028
diff changeset
   863
    /** Throws the exception without telling the verifier. */
36628
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   864
    @ForceInline
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   865
    public void throwException(Throwable ee) {
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   866
        theInternalUnsafe.throwException(ee);
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   867
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   868
90ce3da70b43 Initial load
duke
parents:
diff changeset
   869
    /**
29388
c821b03af80a 8074577: Modernize Unsafe internal javadoc
martin
parents: 29028
diff changeset
   870
     * Atomically updates Java variable to {@code x} if it is currently
c821b03af80a 8074577: Modernize Unsafe internal javadoc
martin
parents: 29028
diff changeset
   871
     * holding {@code expected}.
29715
ca3f43a932cf 8074578: Document memory visibility effects of Unsafe compareAndSwap methods
martin
parents: 29388
diff changeset
   872
     *
ca3f43a932cf 8074578: Document memory visibility effects of Unsafe compareAndSwap methods
martin
parents: 29388
diff changeset
   873
     * <p>This operation has memory semantics of a {@code volatile} read
ca3f43a932cf 8074578: Document memory visibility effects of Unsafe compareAndSwap methods
martin
parents: 29388
diff changeset
   874
     * and write.  Corresponds to C11 atomic_compare_exchange_strong.
ca3f43a932cf 8074578: Document memory visibility effects of Unsafe compareAndSwap methods
martin
parents: 29388
diff changeset
   875
     *
29388
c821b03af80a 8074577: Modernize Unsafe internal javadoc
martin
parents: 29028
diff changeset
   876
     * @return {@code true} if successful
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   877
     */
36628
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   878
    @ForceInline
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   879
    public final boolean compareAndSwapObject(Object o, long offset,
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   880
                                              Object expected,
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   881
                                              Object x) {
45518
4a116dd82fb5 8181292: Backport Rename internal Unsafe.compare methods from 10 to 9
psandoz
parents: 44359
diff changeset
   882
        return theInternalUnsafe.compareAndSetObject(o, offset, expected, x);
36628
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   883
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   884
90ce3da70b43 Initial load
duke
parents:
diff changeset
   885
    /**
29388
c821b03af80a 8074577: Modernize Unsafe internal javadoc
martin
parents: 29028
diff changeset
   886
     * Atomically updates Java variable to {@code x} if it is currently
c821b03af80a 8074577: Modernize Unsafe internal javadoc
martin
parents: 29028
diff changeset
   887
     * holding {@code expected}.
29715
ca3f43a932cf 8074578: Document memory visibility effects of Unsafe compareAndSwap methods
martin
parents: 29388
diff changeset
   888
     *
ca3f43a932cf 8074578: Document memory visibility effects of Unsafe compareAndSwap methods
martin
parents: 29388
diff changeset
   889
     * <p>This operation has memory semantics of a {@code volatile} read
ca3f43a932cf 8074578: Document memory visibility effects of Unsafe compareAndSwap methods
martin
parents: 29388
diff changeset
   890
     * and write.  Corresponds to C11 atomic_compare_exchange_strong.
ca3f43a932cf 8074578: Document memory visibility effects of Unsafe compareAndSwap methods
martin
parents: 29388
diff changeset
   891
     *
29388
c821b03af80a 8074577: Modernize Unsafe internal javadoc
martin
parents: 29028
diff changeset
   892
     * @return {@code true} if successful
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   893
     */
36628
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   894
    @ForceInline
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   895
    public final boolean compareAndSwapInt(Object o, long offset,
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   896
                                           int expected,
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   897
                                           int x) {
45518
4a116dd82fb5 8181292: Backport Rename internal Unsafe.compare methods from 10 to 9
psandoz
parents: 44359
diff changeset
   898
        return theInternalUnsafe.compareAndSetInt(o, offset, expected, x);
36628
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   899
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   900
90ce3da70b43 Initial load
duke
parents:
diff changeset
   901
    /**
29388
c821b03af80a 8074577: Modernize Unsafe internal javadoc
martin
parents: 29028
diff changeset
   902
     * Atomically updates Java variable to {@code x} if it is currently
c821b03af80a 8074577: Modernize Unsafe internal javadoc
martin
parents: 29028
diff changeset
   903
     * holding {@code expected}.
29715
ca3f43a932cf 8074578: Document memory visibility effects of Unsafe compareAndSwap methods
martin
parents: 29388
diff changeset
   904
     *
ca3f43a932cf 8074578: Document memory visibility effects of Unsafe compareAndSwap methods
martin
parents: 29388
diff changeset
   905
     * <p>This operation has memory semantics of a {@code volatile} read
ca3f43a932cf 8074578: Document memory visibility effects of Unsafe compareAndSwap methods
martin
parents: 29388
diff changeset
   906
     * and write.  Corresponds to C11 atomic_compare_exchange_strong.
ca3f43a932cf 8074578: Document memory visibility effects of Unsafe compareAndSwap methods
martin
parents: 29388
diff changeset
   907
     *
29388
c821b03af80a 8074577: Modernize Unsafe internal javadoc
martin
parents: 29028
diff changeset
   908
     * @return {@code true} if successful
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   909
     */
36628
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   910
    @ForceInline
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   911
    public final boolean compareAndSwapLong(Object o, long offset,
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   912
                                            long expected,
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   913
                                            long x) {
45518
4a116dd82fb5 8181292: Backport Rename internal Unsafe.compare methods from 10 to 9
psandoz
parents: 44359
diff changeset
   914
        return theInternalUnsafe.compareAndSetLong(o, offset, expected, x);
36628
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   915
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   916
90ce3da70b43 Initial load
duke
parents:
diff changeset
   917
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   918
     * Fetches a reference value from a given Java variable, with volatile
90ce3da70b43 Initial load
duke
parents:
diff changeset
   919
     * load semantics. Otherwise identical to {@link #getObject(Object, long)}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   920
     */
36628
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   921
    @ForceInline
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   922
    public Object getObjectVolatile(Object o, long offset) {
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   923
        return theInternalUnsafe.getObjectVolatile(o, offset);
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   924
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   925
90ce3da70b43 Initial load
duke
parents:
diff changeset
   926
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   927
     * Stores a reference value into a given Java variable, with
90ce3da70b43 Initial load
duke
parents:
diff changeset
   928
     * volatile store semantics. Otherwise identical to {@link #putObject(Object, long, Object)}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   929
     */
36628
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   930
    @ForceInline
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   931
    public void putObjectVolatile(Object o, long offset, Object x) {
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   932
        theInternalUnsafe.putObjectVolatile(o, offset, x);
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   933
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   934
90ce3da70b43 Initial load
duke
parents:
diff changeset
   935
    /** Volatile version of {@link #getInt(Object, long)}  */
36628
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   936
    @ForceInline
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   937
    public int getIntVolatile(Object o, long offset) {
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   938
        return theInternalUnsafe.getIntVolatile(o, offset);
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   939
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   940
90ce3da70b43 Initial load
duke
parents:
diff changeset
   941
    /** Volatile version of {@link #putInt(Object, long, int)}  */
36628
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   942
    @ForceInline
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   943
    public void putIntVolatile(Object o, long offset, int x) {
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   944
        theInternalUnsafe.putIntVolatile(o, offset, x);
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   945
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   946
90ce3da70b43 Initial load
duke
parents:
diff changeset
   947
    /** Volatile version of {@link #getBoolean(Object, long)}  */
36628
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   948
    @ForceInline
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   949
    public boolean getBooleanVolatile(Object o, long offset) {
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   950
        return theInternalUnsafe.getBooleanVolatile(o, offset);
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   951
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   952
90ce3da70b43 Initial load
duke
parents:
diff changeset
   953
    /** Volatile version of {@link #putBoolean(Object, long, boolean)}  */
36628
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   954
    @ForceInline
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   955
    public void putBooleanVolatile(Object o, long offset, boolean x) {
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   956
        theInternalUnsafe.putBooleanVolatile(o, offset, x);
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   957
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   958
90ce3da70b43 Initial load
duke
parents:
diff changeset
   959
    /** Volatile version of {@link #getByte(Object, long)}  */
36628
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   960
    @ForceInline
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   961
    public byte getByteVolatile(Object o, long offset) {
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   962
        return theInternalUnsafe.getByteVolatile(o, offset);
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   963
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   964
90ce3da70b43 Initial load
duke
parents:
diff changeset
   965
    /** Volatile version of {@link #putByte(Object, long, byte)}  */
36628
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   966
    @ForceInline
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   967
    public void putByteVolatile(Object o, long offset, byte x) {
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   968
        theInternalUnsafe.putByteVolatile(o, offset, x);
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   969
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   970
90ce3da70b43 Initial load
duke
parents:
diff changeset
   971
    /** Volatile version of {@link #getShort(Object, long)}  */
36628
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   972
    @ForceInline
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   973
    public short getShortVolatile(Object o, long offset) {
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   974
        return theInternalUnsafe.getShortVolatile(o, offset);
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   975
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   976
90ce3da70b43 Initial load
duke
parents:
diff changeset
   977
    /** Volatile version of {@link #putShort(Object, long, short)}  */
36628
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   978
    @ForceInline
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   979
    public void putShortVolatile(Object o, long offset, short x) {
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   980
        theInternalUnsafe.putShortVolatile(o, offset, x);
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   981
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   982
90ce3da70b43 Initial load
duke
parents:
diff changeset
   983
    /** Volatile version of {@link #getChar(Object, long)}  */
36628
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   984
    @ForceInline
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   985
    public char getCharVolatile(Object o, long offset) {
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   986
        return theInternalUnsafe.getCharVolatile(o, offset);
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   987
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   988
90ce3da70b43 Initial load
duke
parents:
diff changeset
   989
    /** Volatile version of {@link #putChar(Object, long, char)}  */
36628
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   990
    @ForceInline
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   991
    public void putCharVolatile(Object o, long offset, char x) {
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   992
        theInternalUnsafe.putCharVolatile(o, offset, x);
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   993
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   994
90ce3da70b43 Initial load
duke
parents:
diff changeset
   995
    /** Volatile version of {@link #getLong(Object, long)}  */
36628
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   996
    @ForceInline
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   997
    public long getLongVolatile(Object o, long offset) {
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   998
        return theInternalUnsafe.getLongVolatile(o, offset);
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
   999
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1000
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1001
    /** Volatile version of {@link #putLong(Object, long, long)}  */
36628
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
  1002
    @ForceInline
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
  1003
    public void putLongVolatile(Object o, long offset, long x) {
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
  1004
        theInternalUnsafe.putLongVolatile(o, offset, x);
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
  1005
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1006
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1007
    /** Volatile version of {@link #getFloat(Object, long)}  */
36628
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
  1008
    @ForceInline
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
  1009
    public float getFloatVolatile(Object o, long offset) {
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
  1010
        return theInternalUnsafe.getFloatVolatile(o, offset);
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
  1011
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1012
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1013
    /** Volatile version of {@link #putFloat(Object, long, float)}  */
36628
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
  1014
    @ForceInline
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
  1015
    public void putFloatVolatile(Object o, long offset, float x) {
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
  1016
        theInternalUnsafe.putFloatVolatile(o, offset, x);
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
  1017
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1018
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1019
    /** Volatile version of {@link #getDouble(Object, long)}  */
36628
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
  1020
    @ForceInline
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
  1021
    public double getDoubleVolatile(Object o, long offset) {
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
  1022
        return theInternalUnsafe.getDoubleVolatile(o, offset);
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
  1023
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1024
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1025
    /** Volatile version of {@link #putDouble(Object, long, double)}  */
36628
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
  1026
    @ForceInline
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
  1027
    public void putDoubleVolatile(Object o, long offset, double x) {
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
  1028
        theInternalUnsafe.putDoubleVolatile(o, offset, x);
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
  1029
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1030
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1031
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1032
     * Version of {@link #putObjectVolatile(Object, long, Object)}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1033
     * that does not guarantee immediate visibility of the store to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1034
     * other threads. This method is generally only useful if the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1035
     * underlying field is a Java volatile (or if an array cell, one
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1036
     * that is otherwise only accessed using volatile accesses).
28057
1a47ceecdba5 8065804: JEP 171: Clarifications/corrections for fence intrinsics
martin
parents: 25859
diff changeset
  1037
     *
1a47ceecdba5 8065804: JEP 171: Clarifications/corrections for fence intrinsics
martin
parents: 25859
diff changeset
  1038
     * Corresponds to C11 atomic_store_explicit(..., memory_order_release).
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1039
     */
36628
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
  1040
    @ForceInline
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
  1041
    public void putOrderedObject(Object o, long offset, Object x) {
36936
bfcdf736a998 8152698: Remove obsolete Unsafe.putOrdered{X} methods, usages, runtime and compiler support
shade
parents: 36628
diff changeset
  1042
        theInternalUnsafe.putObjectRelease(o, offset, x);
36628
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
  1043
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1044
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1045
    /** Ordered/Lazy version of {@link #putIntVolatile(Object, long, int)}  */
36628
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
  1046
    @ForceInline
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
  1047
    public void putOrderedInt(Object o, long offset, int x) {
36936
bfcdf736a998 8152698: Remove obsolete Unsafe.putOrdered{X} methods, usages, runtime and compiler support
shade
parents: 36628
diff changeset
  1048
        theInternalUnsafe.putIntRelease(o, offset, x);
36628
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
  1049
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1050
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1051
    /** Ordered/Lazy version of {@link #putLongVolatile(Object, long, long)} */
36628
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
  1052
    @ForceInline
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
  1053
    public void putOrderedLong(Object o, long offset, long x) {
36936
bfcdf736a998 8152698: Remove obsolete Unsafe.putOrdered{X} methods, usages, runtime and compiler support
shade
parents: 36628
diff changeset
  1054
        theInternalUnsafe.putLongRelease(o, offset, x);
36628
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
  1055
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1056
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1057
    /**
29388
c821b03af80a 8074577: Modernize Unsafe internal javadoc
martin
parents: 29028
diff changeset
  1058
     * Unblocks the given thread blocked on {@code park}, or, if it is
c821b03af80a 8074577: Modernize Unsafe internal javadoc
martin
parents: 29028
diff changeset
  1059
     * not blocked, causes the subsequent call to {@code park} not to
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1060
     * block.  Note: this operation is "unsafe" solely because the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1061
     * caller must somehow ensure that the thread has not been
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1062
     * destroyed. Nothing special is usually required to ensure this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1063
     * when called from Java (in which there will ordinarily be a live
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1064
     * reference to the thread) but this is not nearly-automatically
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1065
     * so when calling from native code.
29388
c821b03af80a 8074577: Modernize Unsafe internal javadoc
martin
parents: 29028
diff changeset
  1066
     *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1067
     * @param thread the thread to unpark.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1068
     */
36628
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
  1069
    @ForceInline
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
  1070
    public void unpark(Object thread) {
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
  1071
        theInternalUnsafe.unpark(thread);
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
  1072
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1073
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1074
    /**
29388
c821b03af80a 8074577: Modernize Unsafe internal javadoc
martin
parents: 29028
diff changeset
  1075
     * Blocks current thread, returning when a balancing
c821b03af80a 8074577: Modernize Unsafe internal javadoc
martin
parents: 29028
diff changeset
  1076
     * {@code unpark} occurs, or a balancing {@code unpark} has
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1077
     * already occurred, or the thread is interrupted, or, if not
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1078
     * absolute and time is not zero, the given time nanoseconds have
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1079
     * elapsed, or if absolute, the given deadline in milliseconds
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1080
     * since Epoch has passed, or spuriously (i.e., returning for no
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1081
     * "reason"). Note: This operation is in the Unsafe class only
29388
c821b03af80a 8074577: Modernize Unsafe internal javadoc
martin
parents: 29028
diff changeset
  1082
     * because {@code unpark} is, so it would be strange to place it
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1083
     * elsewhere.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1084
     */
36628
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
  1085
    @ForceInline
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
  1086
    public void park(boolean isAbsolute, long time) {
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
  1087
        theInternalUnsafe.park(isAbsolute, time);
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
  1088
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1089
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1090
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1091
     * Gets the load average in the system run queue assigned
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1092
     * to the available processors averaged over various periods of time.
29388
c821b03af80a 8074577: Modernize Unsafe internal javadoc
martin
parents: 29028
diff changeset
  1093
     * This method retrieves the given {@code nelem} samples and
c821b03af80a 8074577: Modernize Unsafe internal javadoc
martin
parents: 29028
diff changeset
  1094
     * assigns to the elements of the given {@code loadavg} array.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1095
     * The system imposes a maximum of 3 samples, representing
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1096
     * averages over the last 1,  5,  and  15 minutes, respectively.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1097
     *
30655
d83f50188ca9 8080422: some docs cleanup for core libs
avstepan
parents: 30361
diff changeset
  1098
     * @param loadavg an array of double of size nelems
d83f50188ca9 8080422: some docs cleanup for core libs
avstepan
parents: 30361
diff changeset
  1099
     * @param nelems the number of samples to be retrieved and
d83f50188ca9 8080422: some docs cleanup for core libs
avstepan
parents: 30361
diff changeset
  1100
     *        must be 1 to 3.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1101
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1102
     * @return the number of samples actually retrieved; or -1
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1103
     *         if the load average is unobtainable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1104
     */
36628
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
  1105
    @ForceInline
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
  1106
    public int getLoadAverage(double[] loadavg, int nelems) {
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
  1107
        return theInternalUnsafe.getLoadAverage(loadavg, nelems);
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
  1108
    }
14851
5d879715aab6 8004318: JEP-171: Support Unsafe fences intrinsics
kvn
parents: 14342
diff changeset
  1109
14853
72f0bc58bb95 8004330: Add missing Unsafe entry points for addAndGet() family
dl
parents: 14851
diff changeset
  1110
    // The following contain CAS-based Java implementations used on
72f0bc58bb95 8004330: Add missing Unsafe entry points for addAndGet() family
dl
parents: 14851
diff changeset
  1111
    // platforms not supporting native instructions
72f0bc58bb95 8004330: Add missing Unsafe entry points for addAndGet() family
dl
parents: 14851
diff changeset
  1112
72f0bc58bb95 8004330: Add missing Unsafe entry points for addAndGet() family
dl
parents: 14851
diff changeset
  1113
    /**
72f0bc58bb95 8004330: Add missing Unsafe entry points for addAndGet() family
dl
parents: 14851
diff changeset
  1114
     * Atomically adds the given value to the current value of a field
29388
c821b03af80a 8074577: Modernize Unsafe internal javadoc
martin
parents: 29028
diff changeset
  1115
     * or array element within the given object {@code o}
c821b03af80a 8074577: Modernize Unsafe internal javadoc
martin
parents: 29028
diff changeset
  1116
     * at the given {@code offset}.
14853
72f0bc58bb95 8004330: Add missing Unsafe entry points for addAndGet() family
dl
parents: 14851
diff changeset
  1117
     *
72f0bc58bb95 8004330: Add missing Unsafe entry points for addAndGet() family
dl
parents: 14851
diff changeset
  1118
     * @param o object/array to update the field/element in
72f0bc58bb95 8004330: Add missing Unsafe entry points for addAndGet() family
dl
parents: 14851
diff changeset
  1119
     * @param offset field/element offset
72f0bc58bb95 8004330: Add missing Unsafe entry points for addAndGet() family
dl
parents: 14851
diff changeset
  1120
     * @param delta the value to add
72f0bc58bb95 8004330: Add missing Unsafe entry points for addAndGet() family
dl
parents: 14851
diff changeset
  1121
     * @return the previous value
72f0bc58bb95 8004330: Add missing Unsafe entry points for addAndGet() family
dl
parents: 14851
diff changeset
  1122
     * @since 1.8
72f0bc58bb95 8004330: Add missing Unsafe entry points for addAndGet() family
dl
parents: 14851
diff changeset
  1123
     */
36628
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
  1124
    @ForceInline
14853
72f0bc58bb95 8004330: Add missing Unsafe entry points for addAndGet() family
dl
parents: 14851
diff changeset
  1125
    public final int getAndAddInt(Object o, long offset, int delta) {
36628
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
  1126
        return theInternalUnsafe.getAndAddInt(o, offset, delta);
14853
72f0bc58bb95 8004330: Add missing Unsafe entry points for addAndGet() family
dl
parents: 14851
diff changeset
  1127
    }
72f0bc58bb95 8004330: Add missing Unsafe entry points for addAndGet() family
dl
parents: 14851
diff changeset
  1128
72f0bc58bb95 8004330: Add missing Unsafe entry points for addAndGet() family
dl
parents: 14851
diff changeset
  1129
    /**
72f0bc58bb95 8004330: Add missing Unsafe entry points for addAndGet() family
dl
parents: 14851
diff changeset
  1130
     * Atomically adds the given value to the current value of a field
29388
c821b03af80a 8074577: Modernize Unsafe internal javadoc
martin
parents: 29028
diff changeset
  1131
     * or array element within the given object {@code o}
c821b03af80a 8074577: Modernize Unsafe internal javadoc
martin
parents: 29028
diff changeset
  1132
     * at the given {@code offset}.
14853
72f0bc58bb95 8004330: Add missing Unsafe entry points for addAndGet() family
dl
parents: 14851
diff changeset
  1133
     *
72f0bc58bb95 8004330: Add missing Unsafe entry points for addAndGet() family
dl
parents: 14851
diff changeset
  1134
     * @param o object/array to update the field/element in
72f0bc58bb95 8004330: Add missing Unsafe entry points for addAndGet() family
dl
parents: 14851
diff changeset
  1135
     * @param offset field/element offset
72f0bc58bb95 8004330: Add missing Unsafe entry points for addAndGet() family
dl
parents: 14851
diff changeset
  1136
     * @param delta the value to add
72f0bc58bb95 8004330: Add missing Unsafe entry points for addAndGet() family
dl
parents: 14851
diff changeset
  1137
     * @return the previous value
72f0bc58bb95 8004330: Add missing Unsafe entry points for addAndGet() family
dl
parents: 14851
diff changeset
  1138
     * @since 1.8
72f0bc58bb95 8004330: Add missing Unsafe entry points for addAndGet() family
dl
parents: 14851
diff changeset
  1139
     */
36628
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
  1140
    @ForceInline
14853
72f0bc58bb95 8004330: Add missing Unsafe entry points for addAndGet() family
dl
parents: 14851
diff changeset
  1141
    public final long getAndAddLong(Object o, long offset, long delta) {
36628
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
  1142
        return theInternalUnsafe.getAndAddLong(o, offset, delta);
14853
72f0bc58bb95 8004330: Add missing Unsafe entry points for addAndGet() family
dl
parents: 14851
diff changeset
  1143
    }
72f0bc58bb95 8004330: Add missing Unsafe entry points for addAndGet() family
dl
parents: 14851
diff changeset
  1144
72f0bc58bb95 8004330: Add missing Unsafe entry points for addAndGet() family
dl
parents: 14851
diff changeset
  1145
    /**
72f0bc58bb95 8004330: Add missing Unsafe entry points for addAndGet() family
dl
parents: 14851
diff changeset
  1146
     * Atomically exchanges the given value with the current value of
29388
c821b03af80a 8074577: Modernize Unsafe internal javadoc
martin
parents: 29028
diff changeset
  1147
     * a field or array element within the given object {@code o}
c821b03af80a 8074577: Modernize Unsafe internal javadoc
martin
parents: 29028
diff changeset
  1148
     * at the given {@code offset}.
14853
72f0bc58bb95 8004330: Add missing Unsafe entry points for addAndGet() family
dl
parents: 14851
diff changeset
  1149
     *
72f0bc58bb95 8004330: Add missing Unsafe entry points for addAndGet() family
dl
parents: 14851
diff changeset
  1150
     * @param o object/array to update the field/element in
72f0bc58bb95 8004330: Add missing Unsafe entry points for addAndGet() family
dl
parents: 14851
diff changeset
  1151
     * @param offset field/element offset
72f0bc58bb95 8004330: Add missing Unsafe entry points for addAndGet() family
dl
parents: 14851
diff changeset
  1152
     * @param newValue new value
72f0bc58bb95 8004330: Add missing Unsafe entry points for addAndGet() family
dl
parents: 14851
diff changeset
  1153
     * @return the previous value
72f0bc58bb95 8004330: Add missing Unsafe entry points for addAndGet() family
dl
parents: 14851
diff changeset
  1154
     * @since 1.8
72f0bc58bb95 8004330: Add missing Unsafe entry points for addAndGet() family
dl
parents: 14851
diff changeset
  1155
     */
36628
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
  1156
    @ForceInline
14853
72f0bc58bb95 8004330: Add missing Unsafe entry points for addAndGet() family
dl
parents: 14851
diff changeset
  1157
    public final int getAndSetInt(Object o, long offset, int newValue) {
36628
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
  1158
        return theInternalUnsafe.getAndSetInt(o, offset, newValue);
14853
72f0bc58bb95 8004330: Add missing Unsafe entry points for addAndGet() family
dl
parents: 14851
diff changeset
  1159
    }
72f0bc58bb95 8004330: Add missing Unsafe entry points for addAndGet() family
dl
parents: 14851
diff changeset
  1160
72f0bc58bb95 8004330: Add missing Unsafe entry points for addAndGet() family
dl
parents: 14851
diff changeset
  1161
    /**
72f0bc58bb95 8004330: Add missing Unsafe entry points for addAndGet() family
dl
parents: 14851
diff changeset
  1162
     * Atomically exchanges the given value with the current value of
29388
c821b03af80a 8074577: Modernize Unsafe internal javadoc
martin
parents: 29028
diff changeset
  1163
     * a field or array element within the given object {@code o}
c821b03af80a 8074577: Modernize Unsafe internal javadoc
martin
parents: 29028
diff changeset
  1164
     * at the given {@code offset}.
14853
72f0bc58bb95 8004330: Add missing Unsafe entry points for addAndGet() family
dl
parents: 14851
diff changeset
  1165
     *
72f0bc58bb95 8004330: Add missing Unsafe entry points for addAndGet() family
dl
parents: 14851
diff changeset
  1166
     * @param o object/array to update the field/element in
72f0bc58bb95 8004330: Add missing Unsafe entry points for addAndGet() family
dl
parents: 14851
diff changeset
  1167
     * @param offset field/element offset
72f0bc58bb95 8004330: Add missing Unsafe entry points for addAndGet() family
dl
parents: 14851
diff changeset
  1168
     * @param newValue new value
72f0bc58bb95 8004330: Add missing Unsafe entry points for addAndGet() family
dl
parents: 14851
diff changeset
  1169
     * @return the previous value
72f0bc58bb95 8004330: Add missing Unsafe entry points for addAndGet() family
dl
parents: 14851
diff changeset
  1170
     * @since 1.8
72f0bc58bb95 8004330: Add missing Unsafe entry points for addAndGet() family
dl
parents: 14851
diff changeset
  1171
     */
36628
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
  1172
    @ForceInline
14853
72f0bc58bb95 8004330: Add missing Unsafe entry points for addAndGet() family
dl
parents: 14851
diff changeset
  1173
    public final long getAndSetLong(Object o, long offset, long newValue) {
36628
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
  1174
        return theInternalUnsafe.getAndSetLong(o, offset, newValue);
14853
72f0bc58bb95 8004330: Add missing Unsafe entry points for addAndGet() family
dl
parents: 14851
diff changeset
  1175
    }
72f0bc58bb95 8004330: Add missing Unsafe entry points for addAndGet() family
dl
parents: 14851
diff changeset
  1176
72f0bc58bb95 8004330: Add missing Unsafe entry points for addAndGet() family
dl
parents: 14851
diff changeset
  1177
    /**
72f0bc58bb95 8004330: Add missing Unsafe entry points for addAndGet() family
dl
parents: 14851
diff changeset
  1178
     * Atomically exchanges the given reference value with the current
72f0bc58bb95 8004330: Add missing Unsafe entry points for addAndGet() family
dl
parents: 14851
diff changeset
  1179
     * reference value of a field or array element within the given
29388
c821b03af80a 8074577: Modernize Unsafe internal javadoc
martin
parents: 29028
diff changeset
  1180
     * object {@code o} at the given {@code offset}.
14853
72f0bc58bb95 8004330: Add missing Unsafe entry points for addAndGet() family
dl
parents: 14851
diff changeset
  1181
     *
72f0bc58bb95 8004330: Add missing Unsafe entry points for addAndGet() family
dl
parents: 14851
diff changeset
  1182
     * @param o object/array to update the field/element in
72f0bc58bb95 8004330: Add missing Unsafe entry points for addAndGet() family
dl
parents: 14851
diff changeset
  1183
     * @param offset field/element offset
72f0bc58bb95 8004330: Add missing Unsafe entry points for addAndGet() family
dl
parents: 14851
diff changeset
  1184
     * @param newValue new value
72f0bc58bb95 8004330: Add missing Unsafe entry points for addAndGet() family
dl
parents: 14851
diff changeset
  1185
     * @return the previous value
72f0bc58bb95 8004330: Add missing Unsafe entry points for addAndGet() family
dl
parents: 14851
diff changeset
  1186
     * @since 1.8
72f0bc58bb95 8004330: Add missing Unsafe entry points for addAndGet() family
dl
parents: 14851
diff changeset
  1187
     */
36628
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
  1188
    @ForceInline
14853
72f0bc58bb95 8004330: Add missing Unsafe entry points for addAndGet() family
dl
parents: 14851
diff changeset
  1189
    public final Object getAndSetObject(Object o, long offset, Object newValue) {
36628
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
  1190
        return theInternalUnsafe.getAndSetObject(o, offset, newValue);
14853
72f0bc58bb95 8004330: Add missing Unsafe entry points for addAndGet() family
dl
parents: 14851
diff changeset
  1191
    }
72f0bc58bb95 8004330: Add missing Unsafe entry points for addAndGet() family
dl
parents: 14851
diff changeset
  1192
72f0bc58bb95 8004330: Add missing Unsafe entry points for addAndGet() family
dl
parents: 14851
diff changeset
  1193
14851
5d879715aab6 8004318: JEP-171: Support Unsafe fences intrinsics
kvn
parents: 14342
diff changeset
  1194
    /**
28057
1a47ceecdba5 8065804: JEP 171: Clarifications/corrections for fence intrinsics
martin
parents: 25859
diff changeset
  1195
     * Ensures that loads before the fence will not be reordered with loads and
1a47ceecdba5 8065804: JEP 171: Clarifications/corrections for fence intrinsics
martin
parents: 25859
diff changeset
  1196
     * stores after the fence; a "LoadLoad plus LoadStore barrier".
1a47ceecdba5 8065804: JEP 171: Clarifications/corrections for fence intrinsics
martin
parents: 25859
diff changeset
  1197
     *
1a47ceecdba5 8065804: JEP 171: Clarifications/corrections for fence intrinsics
martin
parents: 25859
diff changeset
  1198
     * Corresponds to C11 atomic_thread_fence(memory_order_acquire)
1a47ceecdba5 8065804: JEP 171: Clarifications/corrections for fence intrinsics
martin
parents: 25859
diff changeset
  1199
     * (an "acquire fence").
1a47ceecdba5 8065804: JEP 171: Clarifications/corrections for fence intrinsics
martin
parents: 25859
diff changeset
  1200
     *
1a47ceecdba5 8065804: JEP 171: Clarifications/corrections for fence intrinsics
martin
parents: 25859
diff changeset
  1201
     * A pure LoadLoad fence is not provided, since the addition of LoadStore
1a47ceecdba5 8065804: JEP 171: Clarifications/corrections for fence intrinsics
martin
parents: 25859
diff changeset
  1202
     * is almost always desired, and most current hardware instructions that
1a47ceecdba5 8065804: JEP 171: Clarifications/corrections for fence intrinsics
martin
parents: 25859
diff changeset
  1203
     * provide a LoadLoad barrier also provide a LoadStore barrier for free.
14853
72f0bc58bb95 8004330: Add missing Unsafe entry points for addAndGet() family
dl
parents: 14851
diff changeset
  1204
     * @since 1.8
14851
5d879715aab6 8004318: JEP-171: Support Unsafe fences intrinsics
kvn
parents: 14342
diff changeset
  1205
     */
36628
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
  1206
    @ForceInline
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
  1207
    public void loadFence() {
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
  1208
        theInternalUnsafe.loadFence();
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
  1209
    }
14851
5d879715aab6 8004318: JEP-171: Support Unsafe fences intrinsics
kvn
parents: 14342
diff changeset
  1210
5d879715aab6 8004318: JEP-171: Support Unsafe fences intrinsics
kvn
parents: 14342
diff changeset
  1211
    /**
28057
1a47ceecdba5 8065804: JEP 171: Clarifications/corrections for fence intrinsics
martin
parents: 25859
diff changeset
  1212
     * Ensures that loads and stores before the fence will not be reordered with
1a47ceecdba5 8065804: JEP 171: Clarifications/corrections for fence intrinsics
martin
parents: 25859
diff changeset
  1213
     * stores after the fence; a "StoreStore plus LoadStore barrier".
1a47ceecdba5 8065804: JEP 171: Clarifications/corrections for fence intrinsics
martin
parents: 25859
diff changeset
  1214
     *
1a47ceecdba5 8065804: JEP 171: Clarifications/corrections for fence intrinsics
martin
parents: 25859
diff changeset
  1215
     * Corresponds to C11 atomic_thread_fence(memory_order_release)
1a47ceecdba5 8065804: JEP 171: Clarifications/corrections for fence intrinsics
martin
parents: 25859
diff changeset
  1216
     * (a "release fence").
1a47ceecdba5 8065804: JEP 171: Clarifications/corrections for fence intrinsics
martin
parents: 25859
diff changeset
  1217
     *
1a47ceecdba5 8065804: JEP 171: Clarifications/corrections for fence intrinsics
martin
parents: 25859
diff changeset
  1218
     * A pure StoreStore fence is not provided, since the addition of LoadStore
1a47ceecdba5 8065804: JEP 171: Clarifications/corrections for fence intrinsics
martin
parents: 25859
diff changeset
  1219
     * is almost always desired, and most current hardware instructions that
1a47ceecdba5 8065804: JEP 171: Clarifications/corrections for fence intrinsics
martin
parents: 25859
diff changeset
  1220
     * provide a StoreStore barrier also provide a LoadStore barrier for free.
14853
72f0bc58bb95 8004330: Add missing Unsafe entry points for addAndGet() family
dl
parents: 14851
diff changeset
  1221
     * @since 1.8
14851
5d879715aab6 8004318: JEP-171: Support Unsafe fences intrinsics
kvn
parents: 14342
diff changeset
  1222
     */
36628
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
  1223
    @ForceInline
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
  1224
    public void storeFence() {
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
  1225
        theInternalUnsafe.storeFence();
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
  1226
    }
14851
5d879715aab6 8004318: JEP-171: Support Unsafe fences intrinsics
kvn
parents: 14342
diff changeset
  1227
5d879715aab6 8004318: JEP-171: Support Unsafe fences intrinsics
kvn
parents: 14342
diff changeset
  1228
    /**
28057
1a47ceecdba5 8065804: JEP 171: Clarifications/corrections for fence intrinsics
martin
parents: 25859
diff changeset
  1229
     * Ensures that loads and stores before the fence will not be reordered
1a47ceecdba5 8065804: JEP 171: Clarifications/corrections for fence intrinsics
martin
parents: 25859
diff changeset
  1230
     * with loads and stores after the fence.  Implies the effects of both
1a47ceecdba5 8065804: JEP 171: Clarifications/corrections for fence intrinsics
martin
parents: 25859
diff changeset
  1231
     * loadFence() and storeFence(), and in addition, the effect of a StoreLoad
1a47ceecdba5 8065804: JEP 171: Clarifications/corrections for fence intrinsics
martin
parents: 25859
diff changeset
  1232
     * barrier.
1a47ceecdba5 8065804: JEP 171: Clarifications/corrections for fence intrinsics
martin
parents: 25859
diff changeset
  1233
     *
1a47ceecdba5 8065804: JEP 171: Clarifications/corrections for fence intrinsics
martin
parents: 25859
diff changeset
  1234
     * Corresponds to C11 atomic_thread_fence(memory_order_seq_cst).
14853
72f0bc58bb95 8004330: Add missing Unsafe entry points for addAndGet() family
dl
parents: 14851
diff changeset
  1235
     * @since 1.8
14851
5d879715aab6 8004318: JEP-171: Support Unsafe fences intrinsics
kvn
parents: 14342
diff changeset
  1236
     */
36628
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
  1237
    @ForceInline
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
  1238
    public void fullFence() {
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 35271
diff changeset
  1239
        theInternalUnsafe.fullFence();
21851
f21f49c7c265 8016839: JSR292: AME instead of IAE when calling a method
jrose
parents: 16906
diff changeset
  1240
    }
42707
6059f74bacdf 8171377: Add sun.misc.Unsafe::invokeCleaner
chegar
parents: 38774
diff changeset
  1241
6059f74bacdf 8171377: Add sun.misc.Unsafe::invokeCleaner
chegar
parents: 38774
diff changeset
  1242
    /**
6059f74bacdf 8171377: Add sun.misc.Unsafe::invokeCleaner
chegar
parents: 38774
diff changeset
  1243
     * Invokes the given direct byte buffer's cleaner, if any.
6059f74bacdf 8171377: Add sun.misc.Unsafe::invokeCleaner
chegar
parents: 38774
diff changeset
  1244
     *
6059f74bacdf 8171377: Add sun.misc.Unsafe::invokeCleaner
chegar
parents: 38774
diff changeset
  1245
     * @param directBuffer a direct byte buffer
6059f74bacdf 8171377: Add sun.misc.Unsafe::invokeCleaner
chegar
parents: 38774
diff changeset
  1246
     * @throws NullPointerException if {@code directBuffer} is null
6059f74bacdf 8171377: Add sun.misc.Unsafe::invokeCleaner
chegar
parents: 38774
diff changeset
  1247
     * @throws IllegalArgumentException if {@code directBuffer} is non-direct,
6059f74bacdf 8171377: Add sun.misc.Unsafe::invokeCleaner
chegar
parents: 38774
diff changeset
  1248
     * or is a {@link java.nio.Buffer#slice slice}, or is a
6059f74bacdf 8171377: Add sun.misc.Unsafe::invokeCleaner
chegar
parents: 38774
diff changeset
  1249
     * {@link java.nio.Buffer#duplicate duplicate}
6059f74bacdf 8171377: Add sun.misc.Unsafe::invokeCleaner
chegar
parents: 38774
diff changeset
  1250
     * @since 9
6059f74bacdf 8171377: Add sun.misc.Unsafe::invokeCleaner
chegar
parents: 38774
diff changeset
  1251
     */
6059f74bacdf 8171377: Add sun.misc.Unsafe::invokeCleaner
chegar
parents: 38774
diff changeset
  1252
    public void invokeCleaner(java.nio.ByteBuffer directBuffer) {
6059f74bacdf 8171377: Add sun.misc.Unsafe::invokeCleaner
chegar
parents: 38774
diff changeset
  1253
        if (!directBuffer.isDirect())
6059f74bacdf 8171377: Add sun.misc.Unsafe::invokeCleaner
chegar
parents: 38774
diff changeset
  1254
            throw new IllegalArgumentException("buffer is non-direct");
6059f74bacdf 8171377: Add sun.misc.Unsafe::invokeCleaner
chegar
parents: 38774
diff changeset
  1255
6059f74bacdf 8171377: Add sun.misc.Unsafe::invokeCleaner
chegar
parents: 38774
diff changeset
  1256
        DirectBuffer db = (DirectBuffer)directBuffer;
6059f74bacdf 8171377: Add sun.misc.Unsafe::invokeCleaner
chegar
parents: 38774
diff changeset
  1257
        if (db.attachment() != null)
6059f74bacdf 8171377: Add sun.misc.Unsafe::invokeCleaner
chegar
parents: 38774
diff changeset
  1258
            throw new IllegalArgumentException("duplicate or slice");
6059f74bacdf 8171377: Add sun.misc.Unsafe::invokeCleaner
chegar
parents: 38774
diff changeset
  1259
6059f74bacdf 8171377: Add sun.misc.Unsafe::invokeCleaner
chegar
parents: 38774
diff changeset
  1260
        Cleaner cleaner = db.cleaner();
6059f74bacdf 8171377: Add sun.misc.Unsafe::invokeCleaner
chegar
parents: 38774
diff changeset
  1261
        if (cleaner != null) {
6059f74bacdf 8171377: Add sun.misc.Unsafe::invokeCleaner
chegar
parents: 38774
diff changeset
  1262
            cleaner.clean();
6059f74bacdf 8171377: Add sun.misc.Unsafe::invokeCleaner
chegar
parents: 38774
diff changeset
  1263
        }
6059f74bacdf 8171377: Add sun.misc.Unsafe::invokeCleaner
chegar
parents: 38774
diff changeset
  1264
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1265
}