jdk/src/java.base/share/classes/java/lang/invoke/X-VarHandleByteArrayView.java.template
author psandoz
Thu, 05 May 2016 18:14:47 -0700
changeset 38356 1e4ecca97792
parent 36934 590fc47a0aeb
child 38358 cb99c6d2af1b
permissions -rw-r--r--
8155794: Move Objects.checkIndex BiFunction accepting methods to an internal package Reviewed-by: chegar, shade, forax, vlivanov
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
     1
/*
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
     2
 * Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved.
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
     4
 *
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    10
 *
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    15
 * accompanied this code).
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    16
 *
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    20
 *
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    23
 * questions.
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    24
 */
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    25
package java.lang.invoke;
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    26
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    27
import jdk.internal.misc.Unsafe;
38356
1e4ecca97792 8155794: Move Objects.checkIndex BiFunction accepting methods to an internal package
psandoz
parents: 36934
diff changeset
    28
import jdk.internal.util.Preconditions;
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    29
import jdk.internal.vm.annotation.ForceInline;
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    30
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    31
import java.nio.ByteBuffer;
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    32
import java.nio.ReadOnlyBufferException;
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    33
import java.util.Objects;
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    34
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    35
import static java.lang.invoke.MethodHandleStatics.UNSAFE;
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    36
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    37
#warn
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    38
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    39
final class VarHandleByteArrayAs$Type$s extends VarHandleByteArrayBase {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    40
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    41
    static final int ALIGN = $BoxType$.BYTES - 1;
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    42
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    43
#if[floatingPoint]
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    44
    @ForceInline
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    45
    static $rawType$ convEndian(boolean big, $type$ v) {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    46
        $rawType$ rv = $Type$.$type$ToRaw$RawType$Bits(v);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    47
        return big == BE ? rv : $RawBoxType$.reverseBytes(rv);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    48
    }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    49
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    50
    @ForceInline
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    51
    static $type$ convEndian(boolean big, $rawType$ rv) {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    52
        rv = big == BE ? rv : $RawBoxType$.reverseBytes(rv);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    53
        return $Type$.$rawType$BitsTo$Type$(rv);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    54
    }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    55
#else[floatingPoint]
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    56
    @ForceInline
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    57
    static $type$ convEndian(boolean big, $type$ n) {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    58
        return big == BE ? n : $BoxType$.reverseBytes(n);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    59
    }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    60
#end[floatingPoint]
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    61
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    62
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    63
    private static class ByteArrayViewVarHandle extends VarHandle {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    64
        final boolean be;
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    65
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    66
        ByteArrayViewVarHandle(Class<? extends ByteArrayViewVarHandle> implSubType,
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    67
                               Class<?> arrayType, Class<?> component, boolean be) {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    68
            super(VarForm.createFromStatic(implSubType),
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    69
                  arrayType, component, int.class);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    70
            this.be = be;
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    71
        }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    72
    }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    73
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    74
    static final class ArrayHandle extends ByteArrayViewVarHandle {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    75
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    76
        ArrayHandle(boolean be) {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    77
            super(ArrayHandle.class, byte[].class, $type$.class, be);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    78
        }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    79
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    80
        @ForceInline
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    81
        static int index(byte[] ba, int index) {
38356
1e4ecca97792 8155794: Move Objects.checkIndex BiFunction accepting methods to an internal package
psandoz
parents: 36934
diff changeset
    82
            return Preconditions.checkIndex(index, ba.length - ALIGN, null);
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    83
        }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    84
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    85
        @ForceInline
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    86
        static long address(byte[] ba, int index) {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    87
            long address = ((long) index) + Unsafe.ARRAY_BYTE_BASE_OFFSET;
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    88
            if ((address & ALIGN) != 0)
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    89
                throw newIllegalStateExceptionForMisalignedAccess(index);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    90
            return address;
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    91
        }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    92
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    93
        @ForceInline
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    94
        static $type$ get(ArrayHandle handle, Object oba, int index) {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    95
            byte[] ba = (byte[]) oba;
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    96
#if[floatingPoint]
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    97
            $rawType$ rawValue = UNSAFE.get$RawType$Unaligned(
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    98
                    ba,
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    99
                    ((long) index(ba, index)) + Unsafe.ARRAY_BYTE_BASE_OFFSET,
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   100
                    handle.be);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   101
            return $Type$.$rawType$BitsTo$Type$(rawValue);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   102
#else[floatingPoint]
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   103
            return UNSAFE.get$Type$Unaligned(
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   104
                    ba,
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   105
                    ((long) index(ba, index)) + Unsafe.ARRAY_BYTE_BASE_OFFSET,
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   106
                    handle.be);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   107
#end[floatingPoint]
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   108
        }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   109
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   110
        @ForceInline
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   111
        static void set(ArrayHandle handle, Object oba, int index, $type$ value) {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   112
            byte[] ba = (byte[]) oba;
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   113
#if[floatingPoint]
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   114
            UNSAFE.put$RawType$Unaligned(
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   115
                    ba,
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   116
                    ((long) index(ba, index)) + Unsafe.ARRAY_BYTE_BASE_OFFSET,
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   117
                    $Type$.$type$ToRaw$RawType$Bits(value),
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   118
                    handle.be);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   119
#else[floatingPoint]
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   120
            UNSAFE.put$RawType$Unaligned(
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   121
                    ba,
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   122
                    ((long) index(ba, index)) + Unsafe.ARRAY_BYTE_BASE_OFFSET,
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   123
                    value,
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   124
                    handle.be);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   125
#end[floatingPoint]
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   126
        }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   127
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   128
        @ForceInline
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   129
        static $type$ getVolatile(ArrayHandle handle, Object oba, int index) {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   130
            byte[] ba = (byte[]) oba;
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   131
            return convEndian(handle.be,
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   132
                              UNSAFE.get$RawType$Volatile(
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   133
                                      ba,
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   134
                                      address(ba, index(ba, index))));
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   135
        }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   136
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   137
        @ForceInline
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   138
        static void setVolatile(ArrayHandle handle, Object oba, int index, $type$ value) {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   139
            byte[] ba = (byte[]) oba;
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   140
            UNSAFE.put$RawType$Volatile(
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   141
                    ba,
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   142
                    address(ba, index(ba, index)),
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   143
                    convEndian(handle.be, value));
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   144
        }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   145
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   146
        @ForceInline
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   147
        static $type$ getAcquire(ArrayHandle handle, Object oba, int index) {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   148
            byte[] ba = (byte[]) oba;
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   149
            return convEndian(handle.be,
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   150
                              UNSAFE.get$RawType$Acquire(
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   151
                                      ba,
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   152
                                      address(ba, index(ba, index))));
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   153
        }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   154
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   155
        @ForceInline
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   156
        static void setRelease(ArrayHandle handle, Object oba, int index, $type$ value) {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   157
            byte[] ba = (byte[]) oba;
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   158
            UNSAFE.put$RawType$Release(
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   159
                    ba,
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   160
                    address(ba, index(ba, index)),
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   161
                    convEndian(handle.be, value));
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   162
        }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   163
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   164
        @ForceInline
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   165
        static $type$ getOpaque(ArrayHandle handle, Object oba, int index) {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   166
            byte[] ba = (byte[]) oba;
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   167
            return convEndian(handle.be,
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   168
                              UNSAFE.get$RawType$Opaque(
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   169
                                      ba,
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   170
                                      address(ba, index(ba, index))));
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   171
        }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   172
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   173
        @ForceInline
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   174
        static void setOpaque(ArrayHandle handle, Object oba, int index, $type$ value) {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   175
            byte[] ba = (byte[]) oba;
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   176
            UNSAFE.put$RawType$Opaque(
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   177
                    ba,
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   178
                    address(ba, index(ba, index)),
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   179
                    convEndian(handle.be, value));
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   180
        }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   181
#if[CAS]
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   182
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   183
        @ForceInline
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   184
        static boolean compareAndSet(ArrayHandle handle, Object oba, int index, $type$ expected, $type$ value) {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   185
            byte[] ba = (byte[]) oba;
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   186
            return UNSAFE.compareAndSwap$RawType$(
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   187
                    ba,
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   188
                    address(ba, index(ba, index)),
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   189
                    convEndian(handle.be, expected), convEndian(handle.be, value));
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   190
        }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   191
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   192
        @ForceInline
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   193
        static $type$ compareAndExchangeVolatile(ArrayHandle handle, Object oba, int index, $type$ expected, $type$ value) {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   194
            byte[] ba = (byte[]) oba;
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   195
            return convEndian(handle.be,
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   196
                              UNSAFE.compareAndExchange$RawType$Volatile(
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   197
                                      ba,
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   198
                                      address(ba, index(ba, index)),
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   199
                                      convEndian(handle.be, expected), convEndian(handle.be, value)));
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   200
        }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   201
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   202
        @ForceInline
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   203
        static $type$ compareAndExchangeAcquire(ArrayHandle handle, Object oba, int index, $type$ expected, $type$ value) {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   204
            byte[] ba = (byte[]) oba;
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   205
            return convEndian(handle.be,
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   206
                              UNSAFE.compareAndExchange$RawType$Acquire(
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   207
                                      ba,
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   208
                                      address(ba, index(ba, index)),
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   209
                                      convEndian(handle.be, expected), convEndian(handle.be, value)));
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   210
        }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   211
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   212
        @ForceInline
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   213
        static $type$ compareAndExchangeRelease(ArrayHandle handle, Object oba, int index, $type$ expected, $type$ value) {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   214
            byte[] ba = (byte[]) oba;
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   215
            return convEndian(handle.be,
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   216
                              UNSAFE.compareAndExchange$RawType$Release(
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   217
                                      ba,
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   218
                                      address(ba, index(ba, index)),
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   219
                                      convEndian(handle.be, expected), convEndian(handle.be, value)));
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   220
        }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   221
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   222
        @ForceInline
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   223
        static boolean weakCompareAndSet(ArrayHandle handle, Object oba, int index, $type$ expected, $type$ value) {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   224
            byte[] ba = (byte[]) oba;
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   225
            return UNSAFE.weakCompareAndSwap$RawType$(
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   226
                    ba,
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   227
                    address(ba, index(ba, index)),
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   228
                    convEndian(handle.be, expected), convEndian(handle.be, value));
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   229
        }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   230
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   231
        @ForceInline
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   232
        static boolean weakCompareAndSetAcquire(ArrayHandle handle, Object oba, int index, $type$ expected, $type$ value) {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   233
            byte[] ba = (byte[]) oba;
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   234
            return UNSAFE.weakCompareAndSwap$RawType$Acquire(
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   235
                    ba,
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   236
                    address(ba, index(ba, index)),
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   237
                    convEndian(handle.be, expected), convEndian(handle.be, value));
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   238
        }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   239
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   240
        @ForceInline
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   241
        static boolean weakCompareAndSetRelease(ArrayHandle handle, Object oba, int index, $type$ expected, $type$ value) {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   242
            byte[] ba = (byte[]) oba;
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   243
            return UNSAFE.weakCompareAndSwap$RawType$Release(
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   244
                    ba,
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   245
                    address(ba, index(ba, index)),
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   246
                    convEndian(handle.be, expected), convEndian(handle.be, value));
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   247
        }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   248
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   249
        @ForceInline
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   250
        static $type$ getAndSet(ArrayHandle handle, Object oba, int index, $type$ value) {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   251
            byte[] ba = (byte[]) oba;
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   252
            return convEndian(handle.be,
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   253
                              UNSAFE.getAndSet$RawType$(
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   254
                                      ba,
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   255
                                      address(ba, index(ba, index)),
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   256
                                      convEndian(handle.be, value)));
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   257
        }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   258
#end[CAS]
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   259
#if[AtomicAdd]
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   260
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   261
        @ForceInline
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   262
        static $type$ getAndAdd(ArrayHandle handle, Object oba, int index, $type$ value) {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   263
            byte[] ba = (byte[]) oba;
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   264
            return convEndian(handle.be,
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   265
                              UNSAFE.getAndAdd$RawType$(
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   266
                                      ba,
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   267
                                      address(ba, index(ba, index)),
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   268
                                      convEndian(handle.be, value)));
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   269
        }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   270
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   271
        @ForceInline
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   272
        static $type$ addAndGet(ArrayHandle handle, Object oba, int index, $type$ value) {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   273
            byte[] ba = (byte[]) oba;
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   274
            return convEndian(handle.be, UNSAFE.getAndAdd$RawType$(
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   275
                    ba,
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   276
                    address(ba, index(ba, index)),
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   277
                    convEndian(handle.be, value))) + value;
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   278
        }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   279
#end[AtomicAdd]
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   280
    }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   281
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   282
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   283
    static final class ByteBufferHandle extends ByteArrayViewVarHandle {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   284
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   285
        ByteBufferHandle(boolean be) {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   286
            super(ByteBufferHandle.class, ByteBuffer.class, $type$.class, be);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   287
        }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   288
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   289
        @ForceInline
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   290
        static int index(ByteBuffer bb, int index) {
38356
1e4ecca97792 8155794: Move Objects.checkIndex BiFunction accepting methods to an internal package
psandoz
parents: 36934
diff changeset
   291
            return Preconditions.checkIndex(index, UNSAFE.getInt(bb, BUFFER_LIMIT) - ALIGN, null);
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   292
        }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   293
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   294
        @ForceInline
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   295
        static int indexRO(ByteBuffer bb, int index) {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   296
            if (UNSAFE.getBoolean(bb, BYTE_BUFFER_IS_READ_ONLY))
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   297
                throw new ReadOnlyBufferException();
38356
1e4ecca97792 8155794: Move Objects.checkIndex BiFunction accepting methods to an internal package
psandoz
parents: 36934
diff changeset
   298
            return Preconditions.checkIndex(index, UNSAFE.getInt(bb, BUFFER_LIMIT) - ALIGN, null);
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   299
        }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   300
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   301
        @ForceInline
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   302
        static long address(ByteBuffer bb, int index) {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   303
            long address = ((long) index) + UNSAFE.getLong(bb, BUFFER_ADDRESS);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   304
            if ((address & ALIGN) != 0)
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   305
                throw newIllegalStateExceptionForMisalignedAccess(index);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   306
            return address;
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   307
        }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   308
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   309
        @ForceInline
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   310
        static $type$ get(ByteBufferHandle handle, Object obb, int index) {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   311
            ByteBuffer bb = (ByteBuffer) obb;
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   312
#if[floatingPoint]
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   313
            $rawType$ rawValue = UNSAFE.get$RawType$Unaligned(
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   314
                    UNSAFE.getObject(bb, BYTE_BUFFER_HB),
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   315
                    ((long) index(bb, index)) + UNSAFE.getLong(bb, BUFFER_ADDRESS),
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   316
                    handle.be);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   317
            return $Type$.$rawType$BitsTo$Type$(rawValue);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   318
#else[floatingPoint]
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   319
            return UNSAFE.get$Type$Unaligned(
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   320
                    UNSAFE.getObject(bb, BYTE_BUFFER_HB),
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   321
                    ((long) index(bb, index)) + UNSAFE.getLong(bb, BUFFER_ADDRESS),
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   322
                    handle.be);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   323
#end[floatingPoint]
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   324
        }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   325
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   326
        @ForceInline
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   327
        static void set(ByteBufferHandle handle, Object obb, int index, $type$ value) {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   328
            ByteBuffer bb = (ByteBuffer) obb;
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   329
#if[floatingPoint]
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   330
            UNSAFE.put$RawType$Unaligned(
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   331
                    UNSAFE.getObject(bb, BYTE_BUFFER_HB),
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   332
                    ((long) indexRO(bb, index)) + UNSAFE.getLong(bb, BUFFER_ADDRESS),
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   333
                    $Type$.$type$ToRaw$RawType$Bits(value),
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   334
                    handle.be);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   335
#else[floatingPoint]
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   336
            UNSAFE.put$Type$Unaligned(
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   337
                    UNSAFE.getObject(bb, BYTE_BUFFER_HB),
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   338
                    ((long) indexRO(bb, index)) + UNSAFE.getLong(bb, BUFFER_ADDRESS),
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   339
                    value,
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   340
                    handle.be);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   341
#end[floatingPoint]
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   342
        }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   343
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   344
        @ForceInline
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   345
        static $type$ getVolatile(ByteBufferHandle handle, Object obb, int index) {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   346
            ByteBuffer bb = (ByteBuffer) obb;
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   347
            return convEndian(handle.be,
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   348
                              UNSAFE.get$RawType$Volatile(
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   349
                                      UNSAFE.getObject(bb, BYTE_BUFFER_HB),
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   350
                                      address(bb, index(bb, index))));
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   351
        }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   352
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   353
        @ForceInline
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   354
        static void setVolatile(ByteBufferHandle handle, Object obb, int index, $type$ value) {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   355
            ByteBuffer bb = (ByteBuffer) obb;
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   356
            UNSAFE.put$RawType$Volatile(
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   357
                    UNSAFE.getObject(bb, BYTE_BUFFER_HB),
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   358
                    address(bb, indexRO(bb, index)),
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   359
                    convEndian(handle.be, value));
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   360
        }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   361
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   362
        @ForceInline
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   363
        static $type$ getAcquire(ByteBufferHandle handle, Object obb, int index) {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   364
            ByteBuffer bb = (ByteBuffer) obb;
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   365
            return convEndian(handle.be,
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   366
                              UNSAFE.get$RawType$Acquire(
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   367
                                      UNSAFE.getObject(bb, BYTE_BUFFER_HB),
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   368
                                      address(bb, index(bb, index))));
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   369
        }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   370
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   371
        @ForceInline
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   372
        static void setRelease(ByteBufferHandle handle, Object obb, int index, $type$ value) {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   373
            ByteBuffer bb = (ByteBuffer) obb;
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   374
            UNSAFE.put$RawType$Release(
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   375
                    UNSAFE.getObject(bb, BYTE_BUFFER_HB),
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   376
                    address(bb, indexRO(bb, index)),
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   377
                    convEndian(handle.be, value));
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   378
        }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   379
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   380
        @ForceInline
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   381
        static $type$ getOpaque(ByteBufferHandle handle, Object obb, int index) {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   382
            ByteBuffer bb = (ByteBuffer) obb;
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   383
            return convEndian(handle.be,
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   384
                              UNSAFE.get$RawType$Opaque(
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   385
                                      UNSAFE.getObject(bb, BYTE_BUFFER_HB),
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   386
                                      address(bb, index(bb, index))));
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   387
        }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   388
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   389
        @ForceInline
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   390
        static void setOpaque(ByteBufferHandle handle, Object obb, int index, $type$ value) {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   391
            ByteBuffer bb = (ByteBuffer) obb;
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   392
            UNSAFE.put$RawType$Opaque(
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   393
                    UNSAFE.getObject(bb, BYTE_BUFFER_HB),
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   394
                    address(bb, indexRO(bb, index)),
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   395
                    convEndian(handle.be, value));
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   396
        }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   397
#if[CAS]
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   398
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   399
        @ForceInline
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   400
        static boolean compareAndSet(ByteBufferHandle handle, Object obb, int index, $type$ expected, $type$ value) {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   401
            ByteBuffer bb = (ByteBuffer) obb;
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   402
            return UNSAFE.compareAndSwap$RawType$(
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   403
                    UNSAFE.getObject(bb, BYTE_BUFFER_HB),
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   404
                    address(bb, indexRO(bb, index)),
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   405
                    convEndian(handle.be, expected), convEndian(handle.be, value));
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   406
        }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   407
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   408
        @ForceInline
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   409
        static $type$ compareAndExchangeVolatile(ByteBufferHandle handle, Object obb, int index, $type$ expected, $type$ value) {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   410
            ByteBuffer bb = (ByteBuffer) obb;
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   411
            return convEndian(handle.be,
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   412
                              UNSAFE.compareAndExchange$RawType$Volatile(
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   413
                                      UNSAFE.getObject(bb, BYTE_BUFFER_HB),
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   414
                                      address(bb, indexRO(bb, index)),
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   415
                                      convEndian(handle.be, expected), convEndian(handle.be, value)));
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   416
        }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   417
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   418
        @ForceInline
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   419
        static $type$ compareAndExchangeAcquire(ByteBufferHandle handle, Object obb, int index, $type$ expected, $type$ value) {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   420
            ByteBuffer bb = (ByteBuffer) obb;
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   421
            return convEndian(handle.be,
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   422
                              UNSAFE.compareAndExchange$RawType$Acquire(
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   423
                                      UNSAFE.getObject(bb, BYTE_BUFFER_HB),
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   424
                                      address(bb, indexRO(bb, index)),
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   425
                                      convEndian(handle.be, expected), convEndian(handle.be, value)));
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   426
        }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   427
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   428
        @ForceInline
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   429
        static $type$ compareAndExchangeRelease(ByteBufferHandle handle, Object obb, int index, $type$ expected, $type$ value) {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   430
            ByteBuffer bb = (ByteBuffer) obb;
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   431
            return convEndian(handle.be,
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   432
                              UNSAFE.compareAndExchange$RawType$Release(
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   433
                                      UNSAFE.getObject(bb, BYTE_BUFFER_HB),
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   434
                                      address(bb, indexRO(bb, index)),
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   435
                                      convEndian(handle.be, expected), convEndian(handle.be, value)));
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   436
        }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   437
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   438
        @ForceInline
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   439
        static boolean weakCompareAndSet(ByteBufferHandle handle, Object obb, int index, $type$ expected, $type$ value) {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   440
            ByteBuffer bb = (ByteBuffer) obb;
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   441
            return UNSAFE.weakCompareAndSwap$RawType$(
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   442
                    UNSAFE.getObject(bb, BYTE_BUFFER_HB),
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   443
                    address(bb, indexRO(bb, index)),
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   444
                    convEndian(handle.be, expected), convEndian(handle.be, value));
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   445
        }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   446
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   447
        @ForceInline
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   448
        static boolean weakCompareAndSetAcquire(ByteBufferHandle handle, Object obb, int index, $type$ expected, $type$ value) {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   449
            ByteBuffer bb = (ByteBuffer) obb;
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   450
            return UNSAFE.weakCompareAndSwap$RawType$Acquire(
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   451
                    UNSAFE.getObject(bb, BYTE_BUFFER_HB),
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   452
                    address(bb, indexRO(bb, index)),
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   453
                    convEndian(handle.be, expected), convEndian(handle.be, value));
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   454
        }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   455
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   456
        @ForceInline
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   457
        static boolean weakCompareAndSetRelease(ByteBufferHandle handle, Object obb, int index, $type$ expected, $type$ value) {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   458
            ByteBuffer bb = (ByteBuffer) obb;
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   459
            return UNSAFE.weakCompareAndSwap$RawType$Release(
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   460
                    UNSAFE.getObject(bb, BYTE_BUFFER_HB),
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   461
                    address(bb, indexRO(bb, index)),
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   462
                    convEndian(handle.be, expected), convEndian(handle.be, value));
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   463
        }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   464
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   465
        @ForceInline
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   466
        static $type$ getAndSet(ByteBufferHandle handle, Object obb, int index, $type$ value) {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   467
            ByteBuffer bb = (ByteBuffer) obb;
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   468
            return convEndian(handle.be,
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   469
                              UNSAFE.getAndSet$RawType$(
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   470
                                      UNSAFE.getObject(bb, BYTE_BUFFER_HB),
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   471
                                      address(bb, indexRO(bb, index)),
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   472
                                      convEndian(handle.be, value)));
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   473
        }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   474
#end[CAS]
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   475
#if[AtomicAdd]
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   476
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   477
        @ForceInline
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   478
        static $type$ getAndAdd(ByteBufferHandle handle, Object obb, int index, $type$ value) {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   479
            ByteBuffer bb = (ByteBuffer) obb;
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   480
            return convEndian(handle.be,
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   481
                              UNSAFE.getAndAdd$RawType$(
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   482
                                      UNSAFE.getObject(bb, BYTE_BUFFER_HB),
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   483
                                      address(bb, indexRO(bb, index)),
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   484
                                      convEndian(handle.be, value)));
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   485
        }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   486
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   487
        @ForceInline
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   488
        static $type$ addAndGet(ByteBufferHandle handle, Object obb, int index, $type$ value) {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   489
            ByteBuffer bb = (ByteBuffer) obb;
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   490
            return convEndian(handle.be,
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   491
                              UNSAFE.getAndAdd$RawType$(
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   492
                                      UNSAFE.getObject(bb, BYTE_BUFFER_HB),
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   493
                                      address(bb, indexRO(bb, index)),
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   494
                                      convEndian(handle.be, value))) + value;
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   495
        }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   496
#end[AtomicAdd]
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   497
    }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   498
}