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