2016-03-24 11:21:21 +01:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved.
|
|
|
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
|
|
|
*
|
|
|
|
* This code is free software; you can redistribute it and/or modify it
|
|
|
|
* under the terms of the GNU General Public License version 2 only, as
|
|
|
|
* published by the Free Software Foundation. Oracle designates this
|
|
|
|
* particular file as subject to the "Classpath" exception as provided
|
|
|
|
* by Oracle in the LICENSE file that accompanied this code.
|
|
|
|
*
|
|
|
|
* This code is distributed in the hope that it will be useful, but WITHOUT
|
|
|
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
|
|
* version 2 for more details (a copy is included in the LICENSE file that
|
|
|
|
* accompanied this code).
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License version
|
|
|
|
* 2 along with this work; if not, write to the Free Software Foundation,
|
|
|
|
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
*
|
|
|
|
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
|
|
|
* or visit www.oracle.com if you need additional information or have any
|
|
|
|
* questions.
|
|
|
|
*/
|
|
|
|
package java.lang.invoke;
|
|
|
|
|
|
|
|
import jdk.internal.misc.Unsafe;
|
2016-05-05 18:14:47 -07:00
|
|
|
import jdk.internal.util.Preconditions;
|
2016-03-24 11:21:21 +01:00
|
|
|
import jdk.internal.vm.annotation.ForceInline;
|
|
|
|
|
|
|
|
import java.nio.ByteBuffer;
|
|
|
|
import java.nio.ReadOnlyBufferException;
|
|
|
|
import java.util.Objects;
|
|
|
|
|
|
|
|
import static java.lang.invoke.MethodHandleStatics.UNSAFE;
|
|
|
|
|
|
|
|
#warn
|
|
|
|
|
|
|
|
final class VarHandleByteArrayAs$Type$s extends VarHandleByteArrayBase {
|
|
|
|
|
|
|
|
static final int ALIGN = $BoxType$.BYTES - 1;
|
|
|
|
|
|
|
|
#if[floatingPoint]
|
|
|
|
@ForceInline
|
|
|
|
static $rawType$ convEndian(boolean big, $type$ v) {
|
|
|
|
$rawType$ rv = $Type$.$type$ToRaw$RawType$Bits(v);
|
|
|
|
return big == BE ? rv : $RawBoxType$.reverseBytes(rv);
|
|
|
|
}
|
|
|
|
|
|
|
|
@ForceInline
|
|
|
|
static $type$ convEndian(boolean big, $rawType$ rv) {
|
|
|
|
rv = big == BE ? rv : $RawBoxType$.reverseBytes(rv);
|
|
|
|
return $Type$.$rawType$BitsTo$Type$(rv);
|
|
|
|
}
|
|
|
|
#else[floatingPoint]
|
|
|
|
@ForceInline
|
|
|
|
static $type$ convEndian(boolean big, $type$ n) {
|
|
|
|
return big == BE ? n : $BoxType$.reverseBytes(n);
|
|
|
|
}
|
|
|
|
#end[floatingPoint]
|
|
|
|
|
|
|
|
|
2016-05-05 11:39:08 -07:00
|
|
|
private static abstract class ByteArrayViewVarHandle extends VarHandle {
|
2016-03-24 11:21:21 +01:00
|
|
|
final boolean be;
|
|
|
|
|
2016-05-05 11:39:08 -07:00
|
|
|
ByteArrayViewVarHandle(VarForm form, boolean be) {
|
|
|
|
super(form);
|
2016-03-24 11:21:21 +01:00
|
|
|
this.be = be;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static final class ArrayHandle extends ByteArrayViewVarHandle {
|
|
|
|
|
|
|
|
ArrayHandle(boolean be) {
|
2016-05-05 11:39:08 -07:00
|
|
|
super(ArrayHandle.FORM, be);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
final MethodType accessModeTypeUncached(AccessMode accessMode) {
|
|
|
|
return accessMode.at.accessModeType(byte[].class, $type$.class, int.class);
|
2016-03-24 11:21:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@ForceInline
|
|
|
|
static int index(byte[] ba, int index) {
|
2016-05-05 18:14:47 -07:00
|
|
|
return Preconditions.checkIndex(index, ba.length - ALIGN, null);
|
2016-03-24 11:21:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@ForceInline
|
|
|
|
static long address(byte[] ba, int index) {
|
|
|
|
long address = ((long) index) + Unsafe.ARRAY_BYTE_BASE_OFFSET;
|
|
|
|
if ((address & ALIGN) != 0)
|
|
|
|
throw newIllegalStateExceptionForMisalignedAccess(index);
|
|
|
|
return address;
|
|
|
|
}
|
|
|
|
|
|
|
|
@ForceInline
|
|
|
|
static $type$ get(ArrayHandle handle, Object oba, int index) {
|
|
|
|
byte[] ba = (byte[]) oba;
|
|
|
|
#if[floatingPoint]
|
|
|
|
$rawType$ rawValue = UNSAFE.get$RawType$Unaligned(
|
|
|
|
ba,
|
|
|
|
((long) index(ba, index)) + Unsafe.ARRAY_BYTE_BASE_OFFSET,
|
|
|
|
handle.be);
|
|
|
|
return $Type$.$rawType$BitsTo$Type$(rawValue);
|
|
|
|
#else[floatingPoint]
|
|
|
|
return UNSAFE.get$Type$Unaligned(
|
|
|
|
ba,
|
|
|
|
((long) index(ba, index)) + Unsafe.ARRAY_BYTE_BASE_OFFSET,
|
|
|
|
handle.be);
|
|
|
|
#end[floatingPoint]
|
|
|
|
}
|
|
|
|
|
|
|
|
@ForceInline
|
|
|
|
static void set(ArrayHandle handle, Object oba, int index, $type$ value) {
|
|
|
|
byte[] ba = (byte[]) oba;
|
|
|
|
#if[floatingPoint]
|
|
|
|
UNSAFE.put$RawType$Unaligned(
|
|
|
|
ba,
|
|
|
|
((long) index(ba, index)) + Unsafe.ARRAY_BYTE_BASE_OFFSET,
|
|
|
|
$Type$.$type$ToRaw$RawType$Bits(value),
|
|
|
|
handle.be);
|
|
|
|
#else[floatingPoint]
|
|
|
|
UNSAFE.put$RawType$Unaligned(
|
|
|
|
ba,
|
|
|
|
((long) index(ba, index)) + Unsafe.ARRAY_BYTE_BASE_OFFSET,
|
|
|
|
value,
|
|
|
|
handle.be);
|
|
|
|
#end[floatingPoint]
|
|
|
|
}
|
|
|
|
|
|
|
|
@ForceInline
|
|
|
|
static $type$ getVolatile(ArrayHandle handle, Object oba, int index) {
|
|
|
|
byte[] ba = (byte[]) oba;
|
|
|
|
return convEndian(handle.be,
|
|
|
|
UNSAFE.get$RawType$Volatile(
|
|
|
|
ba,
|
|
|
|
address(ba, index(ba, index))));
|
|
|
|
}
|
|
|
|
|
|
|
|
@ForceInline
|
|
|
|
static void setVolatile(ArrayHandle handle, Object oba, int index, $type$ value) {
|
|
|
|
byte[] ba = (byte[]) oba;
|
|
|
|
UNSAFE.put$RawType$Volatile(
|
|
|
|
ba,
|
|
|
|
address(ba, index(ba, index)),
|
|
|
|
convEndian(handle.be, value));
|
|
|
|
}
|
|
|
|
|
|
|
|
@ForceInline
|
|
|
|
static $type$ getAcquire(ArrayHandle handle, Object oba, int index) {
|
|
|
|
byte[] ba = (byte[]) oba;
|
|
|
|
return convEndian(handle.be,
|
|
|
|
UNSAFE.get$RawType$Acquire(
|
|
|
|
ba,
|
|
|
|
address(ba, index(ba, index))));
|
|
|
|
}
|
|
|
|
|
|
|
|
@ForceInline
|
|
|
|
static void setRelease(ArrayHandle handle, Object oba, int index, $type$ value) {
|
|
|
|
byte[] ba = (byte[]) oba;
|
|
|
|
UNSAFE.put$RawType$Release(
|
|
|
|
ba,
|
|
|
|
address(ba, index(ba, index)),
|
|
|
|
convEndian(handle.be, value));
|
|
|
|
}
|
|
|
|
|
|
|
|
@ForceInline
|
|
|
|
static $type$ getOpaque(ArrayHandle handle, Object oba, int index) {
|
|
|
|
byte[] ba = (byte[]) oba;
|
|
|
|
return convEndian(handle.be,
|
|
|
|
UNSAFE.get$RawType$Opaque(
|
|
|
|
ba,
|
|
|
|
address(ba, index(ba, index))));
|
|
|
|
}
|
|
|
|
|
|
|
|
@ForceInline
|
|
|
|
static void setOpaque(ArrayHandle handle, Object oba, int index, $type$ value) {
|
|
|
|
byte[] ba = (byte[]) oba;
|
|
|
|
UNSAFE.put$RawType$Opaque(
|
|
|
|
ba,
|
|
|
|
address(ba, index(ba, index)),
|
|
|
|
convEndian(handle.be, value));
|
|
|
|
}
|
|
|
|
#if[CAS]
|
|
|
|
|
|
|
|
@ForceInline
|
|
|
|
static boolean compareAndSet(ArrayHandle handle, Object oba, int index, $type$ expected, $type$ value) {
|
|
|
|
byte[] ba = (byte[]) oba;
|
|
|
|
return UNSAFE.compareAndSwap$RawType$(
|
|
|
|
ba,
|
|
|
|
address(ba, index(ba, index)),
|
|
|
|
convEndian(handle.be, expected), convEndian(handle.be, value));
|
|
|
|
}
|
|
|
|
|
|
|
|
@ForceInline
|
|
|
|
static $type$ compareAndExchangeVolatile(ArrayHandle handle, Object oba, int index, $type$ expected, $type$ value) {
|
|
|
|
byte[] ba = (byte[]) oba;
|
|
|
|
return convEndian(handle.be,
|
|
|
|
UNSAFE.compareAndExchange$RawType$Volatile(
|
|
|
|
ba,
|
|
|
|
address(ba, index(ba, index)),
|
|
|
|
convEndian(handle.be, expected), convEndian(handle.be, value)));
|
|
|
|
}
|
|
|
|
|
|
|
|
@ForceInline
|
|
|
|
static $type$ compareAndExchangeAcquire(ArrayHandle handle, Object oba, int index, $type$ expected, $type$ value) {
|
|
|
|
byte[] ba = (byte[]) oba;
|
|
|
|
return convEndian(handle.be,
|
|
|
|
UNSAFE.compareAndExchange$RawType$Acquire(
|
|
|
|
ba,
|
|
|
|
address(ba, index(ba, index)),
|
|
|
|
convEndian(handle.be, expected), convEndian(handle.be, value)));
|
|
|
|
}
|
|
|
|
|
|
|
|
@ForceInline
|
|
|
|
static $type$ compareAndExchangeRelease(ArrayHandle handle, Object oba, int index, $type$ expected, $type$ value) {
|
|
|
|
byte[] ba = (byte[]) oba;
|
|
|
|
return convEndian(handle.be,
|
|
|
|
UNSAFE.compareAndExchange$RawType$Release(
|
|
|
|
ba,
|
|
|
|
address(ba, index(ba, index)),
|
|
|
|
convEndian(handle.be, expected), convEndian(handle.be, value)));
|
|
|
|
}
|
|
|
|
|
|
|
|
@ForceInline
|
|
|
|
static boolean weakCompareAndSet(ArrayHandle handle, Object oba, int index, $type$ expected, $type$ value) {
|
|
|
|
byte[] ba = (byte[]) oba;
|
|
|
|
return UNSAFE.weakCompareAndSwap$RawType$(
|
|
|
|
ba,
|
|
|
|
address(ba, index(ba, index)),
|
|
|
|
convEndian(handle.be, expected), convEndian(handle.be, value));
|
|
|
|
}
|
|
|
|
|
2016-04-29 13:46:19 -07:00
|
|
|
@ForceInline
|
|
|
|
static boolean weakCompareAndSetVolatile(ArrayHandle handle, Object oba, int index, $type$ expected, $type$ value) {
|
|
|
|
byte[] ba = (byte[]) oba;
|
2016-05-17 22:28:00 +03:00
|
|
|
return UNSAFE.weakCompareAndSwap$RawType$Volatile(
|
2016-04-29 13:46:19 -07:00
|
|
|
ba,
|
|
|
|
address(ba, index(ba, index)),
|
|
|
|
convEndian(handle.be, expected), convEndian(handle.be, value));
|
|
|
|
}
|
|
|
|
|
2016-03-24 11:21:21 +01:00
|
|
|
@ForceInline
|
|
|
|
static boolean weakCompareAndSetAcquire(ArrayHandle handle, Object oba, int index, $type$ expected, $type$ value) {
|
|
|
|
byte[] ba = (byte[]) oba;
|
|
|
|
return UNSAFE.weakCompareAndSwap$RawType$Acquire(
|
|
|
|
ba,
|
|
|
|
address(ba, index(ba, index)),
|
|
|
|
convEndian(handle.be, expected), convEndian(handle.be, value));
|
|
|
|
}
|
|
|
|
|
|
|
|
@ForceInline
|
|
|
|
static boolean weakCompareAndSetRelease(ArrayHandle handle, Object oba, int index, $type$ expected, $type$ value) {
|
|
|
|
byte[] ba = (byte[]) oba;
|
|
|
|
return UNSAFE.weakCompareAndSwap$RawType$Release(
|
|
|
|
ba,
|
|
|
|
address(ba, index(ba, index)),
|
|
|
|
convEndian(handle.be, expected), convEndian(handle.be, value));
|
|
|
|
}
|
|
|
|
|
|
|
|
@ForceInline
|
|
|
|
static $type$ getAndSet(ArrayHandle handle, Object oba, int index, $type$ value) {
|
|
|
|
byte[] ba = (byte[]) oba;
|
|
|
|
return convEndian(handle.be,
|
|
|
|
UNSAFE.getAndSet$RawType$(
|
|
|
|
ba,
|
|
|
|
address(ba, index(ba, index)),
|
|
|
|
convEndian(handle.be, value)));
|
|
|
|
}
|
|
|
|
#end[CAS]
|
|
|
|
#if[AtomicAdd]
|
|
|
|
|
|
|
|
@ForceInline
|
2016-05-18 18:46:14 +02:00
|
|
|
static $type$ getAndAdd(ArrayHandle handle, Object oba, int index, $type$ delta) {
|
2016-03-24 11:21:21 +01:00
|
|
|
byte[] ba = (byte[]) oba;
|
2016-05-18 18:46:14 +02:00
|
|
|
if (handle.be == BE) {
|
|
|
|
return UNSAFE.getAndAdd$RawType$(
|
|
|
|
ba,
|
|
|
|
address(ba, index(ba, index)),
|
|
|
|
delta);
|
|
|
|
} else {
|
|
|
|
return getAndAddConvEndianWithCAS(ba, index, delta);
|
|
|
|
}
|
2016-03-24 11:21:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@ForceInline
|
2016-05-18 18:46:14 +02:00
|
|
|
static $type$ getAndAddConvEndianWithCAS(byte[] ba, int index, $type$ delta) {
|
|
|
|
$type$ nativeExpectedValue, expectedValue;
|
|
|
|
long offset = address(ba, index(ba, index));
|
|
|
|
do {
|
|
|
|
nativeExpectedValue = UNSAFE.get$RawType$Volatile(ba, offset);
|
|
|
|
expectedValue = $RawBoxType$.reverseBytes(nativeExpectedValue);
|
|
|
|
} while (!UNSAFE.weakCompareAndSwap$RawType$Volatile(ba, offset,
|
|
|
|
nativeExpectedValue, $RawBoxType$.reverseBytes(expectedValue + delta)));
|
|
|
|
return expectedValue;
|
|
|
|
}
|
|
|
|
|
|
|
|
@ForceInline
|
|
|
|
static $type$ addAndGet(ArrayHandle handle, Object oba, int index, $type$ delta) {
|
|
|
|
return getAndAdd(handle, oba, index, delta) + delta;
|
2016-03-24 11:21:21 +01:00
|
|
|
}
|
|
|
|
#end[AtomicAdd]
|
2016-05-05 11:39:08 -07:00
|
|
|
|
|
|
|
static final VarForm FORM = new VarForm(ArrayHandle.class, byte[].class, $type$.class, int.class);
|
2016-03-24 11:21:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static final class ByteBufferHandle extends ByteArrayViewVarHandle {
|
|
|
|
|
|
|
|
ByteBufferHandle(boolean be) {
|
2016-05-05 11:39:08 -07:00
|
|
|
super(ByteBufferHandle.FORM, be);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
final MethodType accessModeTypeUncached(AccessMode accessMode) {
|
|
|
|
return accessMode.at.accessModeType(ByteBuffer.class, $type$.class, int.class);
|
2016-03-24 11:21:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@ForceInline
|
|
|
|
static int index(ByteBuffer bb, int index) {
|
2016-05-05 18:14:47 -07:00
|
|
|
return Preconditions.checkIndex(index, UNSAFE.getInt(bb, BUFFER_LIMIT) - ALIGN, null);
|
2016-03-24 11:21:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@ForceInline
|
|
|
|
static int indexRO(ByteBuffer bb, int index) {
|
|
|
|
if (UNSAFE.getBoolean(bb, BYTE_BUFFER_IS_READ_ONLY))
|
|
|
|
throw new ReadOnlyBufferException();
|
2016-05-05 18:14:47 -07:00
|
|
|
return Preconditions.checkIndex(index, UNSAFE.getInt(bb, BUFFER_LIMIT) - ALIGN, null);
|
2016-03-24 11:21:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@ForceInline
|
|
|
|
static long address(ByteBuffer bb, int index) {
|
|
|
|
long address = ((long) index) + UNSAFE.getLong(bb, BUFFER_ADDRESS);
|
|
|
|
if ((address & ALIGN) != 0)
|
|
|
|
throw newIllegalStateExceptionForMisalignedAccess(index);
|
|
|
|
return address;
|
|
|
|
}
|
|
|
|
|
|
|
|
@ForceInline
|
|
|
|
static $type$ get(ByteBufferHandle handle, Object obb, int index) {
|
|
|
|
ByteBuffer bb = (ByteBuffer) obb;
|
|
|
|
#if[floatingPoint]
|
|
|
|
$rawType$ rawValue = UNSAFE.get$RawType$Unaligned(
|
|
|
|
UNSAFE.getObject(bb, BYTE_BUFFER_HB),
|
|
|
|
((long) index(bb, index)) + UNSAFE.getLong(bb, BUFFER_ADDRESS),
|
|
|
|
handle.be);
|
|
|
|
return $Type$.$rawType$BitsTo$Type$(rawValue);
|
|
|
|
#else[floatingPoint]
|
|
|
|
return UNSAFE.get$Type$Unaligned(
|
|
|
|
UNSAFE.getObject(bb, BYTE_BUFFER_HB),
|
|
|
|
((long) index(bb, index)) + UNSAFE.getLong(bb, BUFFER_ADDRESS),
|
|
|
|
handle.be);
|
|
|
|
#end[floatingPoint]
|
|
|
|
}
|
|
|
|
|
|
|
|
@ForceInline
|
|
|
|
static void set(ByteBufferHandle handle, Object obb, int index, $type$ value) {
|
|
|
|
ByteBuffer bb = (ByteBuffer) obb;
|
|
|
|
#if[floatingPoint]
|
|
|
|
UNSAFE.put$RawType$Unaligned(
|
|
|
|
UNSAFE.getObject(bb, BYTE_BUFFER_HB),
|
|
|
|
((long) indexRO(bb, index)) + UNSAFE.getLong(bb, BUFFER_ADDRESS),
|
|
|
|
$Type$.$type$ToRaw$RawType$Bits(value),
|
|
|
|
handle.be);
|
|
|
|
#else[floatingPoint]
|
|
|
|
UNSAFE.put$Type$Unaligned(
|
|
|
|
UNSAFE.getObject(bb, BYTE_BUFFER_HB),
|
|
|
|
((long) indexRO(bb, index)) + UNSAFE.getLong(bb, BUFFER_ADDRESS),
|
|
|
|
value,
|
|
|
|
handle.be);
|
|
|
|
#end[floatingPoint]
|
|
|
|
}
|
|
|
|
|
|
|
|
@ForceInline
|
|
|
|
static $type$ getVolatile(ByteBufferHandle handle, Object obb, int index) {
|
|
|
|
ByteBuffer bb = (ByteBuffer) obb;
|
|
|
|
return convEndian(handle.be,
|
|
|
|
UNSAFE.get$RawType$Volatile(
|
|
|
|
UNSAFE.getObject(bb, BYTE_BUFFER_HB),
|
|
|
|
address(bb, index(bb, index))));
|
|
|
|
}
|
|
|
|
|
|
|
|
@ForceInline
|
|
|
|
static void setVolatile(ByteBufferHandle handle, Object obb, int index, $type$ value) {
|
|
|
|
ByteBuffer bb = (ByteBuffer) obb;
|
|
|
|
UNSAFE.put$RawType$Volatile(
|
|
|
|
UNSAFE.getObject(bb, BYTE_BUFFER_HB),
|
|
|
|
address(bb, indexRO(bb, index)),
|
|
|
|
convEndian(handle.be, value));
|
|
|
|
}
|
|
|
|
|
|
|
|
@ForceInline
|
|
|
|
static $type$ getAcquire(ByteBufferHandle handle, Object obb, int index) {
|
|
|
|
ByteBuffer bb = (ByteBuffer) obb;
|
|
|
|
return convEndian(handle.be,
|
|
|
|
UNSAFE.get$RawType$Acquire(
|
|
|
|
UNSAFE.getObject(bb, BYTE_BUFFER_HB),
|
|
|
|
address(bb, index(bb, index))));
|
|
|
|
}
|
|
|
|
|
|
|
|
@ForceInline
|
|
|
|
static void setRelease(ByteBufferHandle handle, Object obb, int index, $type$ value) {
|
|
|
|
ByteBuffer bb = (ByteBuffer) obb;
|
|
|
|
UNSAFE.put$RawType$Release(
|
|
|
|
UNSAFE.getObject(bb, BYTE_BUFFER_HB),
|
|
|
|
address(bb, indexRO(bb, index)),
|
|
|
|
convEndian(handle.be, value));
|
|
|
|
}
|
|
|
|
|
|
|
|
@ForceInline
|
|
|
|
static $type$ getOpaque(ByteBufferHandle handle, Object obb, int index) {
|
|
|
|
ByteBuffer bb = (ByteBuffer) obb;
|
|
|
|
return convEndian(handle.be,
|
|
|
|
UNSAFE.get$RawType$Opaque(
|
|
|
|
UNSAFE.getObject(bb, BYTE_BUFFER_HB),
|
|
|
|
address(bb, index(bb, index))));
|
|
|
|
}
|
|
|
|
|
|
|
|
@ForceInline
|
|
|
|
static void setOpaque(ByteBufferHandle handle, Object obb, int index, $type$ value) {
|
|
|
|
ByteBuffer bb = (ByteBuffer) obb;
|
|
|
|
UNSAFE.put$RawType$Opaque(
|
|
|
|
UNSAFE.getObject(bb, BYTE_BUFFER_HB),
|
|
|
|
address(bb, indexRO(bb, index)),
|
|
|
|
convEndian(handle.be, value));
|
|
|
|
}
|
|
|
|
#if[CAS]
|
|
|
|
|
|
|
|
@ForceInline
|
|
|
|
static boolean compareAndSet(ByteBufferHandle handle, Object obb, int index, $type$ expected, $type$ value) {
|
|
|
|
ByteBuffer bb = (ByteBuffer) obb;
|
|
|
|
return UNSAFE.compareAndSwap$RawType$(
|
|
|
|
UNSAFE.getObject(bb, BYTE_BUFFER_HB),
|
|
|
|
address(bb, indexRO(bb, index)),
|
|
|
|
convEndian(handle.be, expected), convEndian(handle.be, value));
|
|
|
|
}
|
|
|
|
|
|
|
|
@ForceInline
|
|
|
|
static $type$ compareAndExchangeVolatile(ByteBufferHandle handle, Object obb, int index, $type$ expected, $type$ value) {
|
|
|
|
ByteBuffer bb = (ByteBuffer) obb;
|
|
|
|
return convEndian(handle.be,
|
|
|
|
UNSAFE.compareAndExchange$RawType$Volatile(
|
|
|
|
UNSAFE.getObject(bb, BYTE_BUFFER_HB),
|
|
|
|
address(bb, indexRO(bb, index)),
|
|
|
|
convEndian(handle.be, expected), convEndian(handle.be, value)));
|
|
|
|
}
|
|
|
|
|
|
|
|
@ForceInline
|
|
|
|
static $type$ compareAndExchangeAcquire(ByteBufferHandle handle, Object obb, int index, $type$ expected, $type$ value) {
|
|
|
|
ByteBuffer bb = (ByteBuffer) obb;
|
|
|
|
return convEndian(handle.be,
|
|
|
|
UNSAFE.compareAndExchange$RawType$Acquire(
|
|
|
|
UNSAFE.getObject(bb, BYTE_BUFFER_HB),
|
|
|
|
address(bb, indexRO(bb, index)),
|
|
|
|
convEndian(handle.be, expected), convEndian(handle.be, value)));
|
|
|
|
}
|
|
|
|
|
|
|
|
@ForceInline
|
|
|
|
static $type$ compareAndExchangeRelease(ByteBufferHandle handle, Object obb, int index, $type$ expected, $type$ value) {
|
|
|
|
ByteBuffer bb = (ByteBuffer) obb;
|
|
|
|
return convEndian(handle.be,
|
|
|
|
UNSAFE.compareAndExchange$RawType$Release(
|
|
|
|
UNSAFE.getObject(bb, BYTE_BUFFER_HB),
|
|
|
|
address(bb, indexRO(bb, index)),
|
|
|
|
convEndian(handle.be, expected), convEndian(handle.be, value)));
|
|
|
|
}
|
|
|
|
|
|
|
|
@ForceInline
|
|
|
|
static boolean weakCompareAndSet(ByteBufferHandle handle, Object obb, int index, $type$ expected, $type$ value) {
|
|
|
|
ByteBuffer bb = (ByteBuffer) obb;
|
|
|
|
return UNSAFE.weakCompareAndSwap$RawType$(
|
|
|
|
UNSAFE.getObject(bb, BYTE_BUFFER_HB),
|
|
|
|
address(bb, indexRO(bb, index)),
|
|
|
|
convEndian(handle.be, expected), convEndian(handle.be, value));
|
|
|
|
}
|
|
|
|
|
2016-04-29 13:46:19 -07:00
|
|
|
@ForceInline
|
|
|
|
static boolean weakCompareAndSetVolatile(ByteBufferHandle handle, Object obb, int index, $type$ expected, $type$ value) {
|
|
|
|
ByteBuffer bb = (ByteBuffer) obb;
|
2016-05-17 22:28:00 +03:00
|
|
|
return UNSAFE.weakCompareAndSwap$RawType$Volatile(
|
2016-04-29 13:46:19 -07:00
|
|
|
UNSAFE.getObject(bb, BYTE_BUFFER_HB),
|
|
|
|
address(bb, indexRO(bb, index)),
|
|
|
|
convEndian(handle.be, expected), convEndian(handle.be, value));
|
|
|
|
}
|
|
|
|
|
2016-03-24 11:21:21 +01:00
|
|
|
@ForceInline
|
|
|
|
static boolean weakCompareAndSetAcquire(ByteBufferHandle handle, Object obb, int index, $type$ expected, $type$ value) {
|
|
|
|
ByteBuffer bb = (ByteBuffer) obb;
|
|
|
|
return UNSAFE.weakCompareAndSwap$RawType$Acquire(
|
|
|
|
UNSAFE.getObject(bb, BYTE_BUFFER_HB),
|
|
|
|
address(bb, indexRO(bb, index)),
|
|
|
|
convEndian(handle.be, expected), convEndian(handle.be, value));
|
|
|
|
}
|
|
|
|
|
|
|
|
@ForceInline
|
|
|
|
static boolean weakCompareAndSetRelease(ByteBufferHandle handle, Object obb, int index, $type$ expected, $type$ value) {
|
|
|
|
ByteBuffer bb = (ByteBuffer) obb;
|
|
|
|
return UNSAFE.weakCompareAndSwap$RawType$Release(
|
|
|
|
UNSAFE.getObject(bb, BYTE_BUFFER_HB),
|
|
|
|
address(bb, indexRO(bb, index)),
|
|
|
|
convEndian(handle.be, expected), convEndian(handle.be, value));
|
|
|
|
}
|
|
|
|
|
|
|
|
@ForceInline
|
|
|
|
static $type$ getAndSet(ByteBufferHandle handle, Object obb, int index, $type$ value) {
|
|
|
|
ByteBuffer bb = (ByteBuffer) obb;
|
|
|
|
return convEndian(handle.be,
|
|
|
|
UNSAFE.getAndSet$RawType$(
|
|
|
|
UNSAFE.getObject(bb, BYTE_BUFFER_HB),
|
|
|
|
address(bb, indexRO(bb, index)),
|
|
|
|
convEndian(handle.be, value)));
|
|
|
|
}
|
|
|
|
#end[CAS]
|
|
|
|
#if[AtomicAdd]
|
|
|
|
|
|
|
|
@ForceInline
|
2016-05-18 18:46:14 +02:00
|
|
|
static $type$ getAndAdd(ByteBufferHandle handle, Object obb, int index, $type$ delta) {
|
2016-03-24 11:21:21 +01:00
|
|
|
ByteBuffer bb = (ByteBuffer) obb;
|
2016-05-18 18:46:14 +02:00
|
|
|
if (handle.be == BE) {
|
|
|
|
return UNSAFE.getAndAdd$RawType$(
|
|
|
|
UNSAFE.getObject(bb, BYTE_BUFFER_HB),
|
|
|
|
address(bb, indexRO(bb, index)),
|
|
|
|
delta);
|
|
|
|
} else {
|
|
|
|
return getAndAddConvEndianWithCAS(bb, index, delta);
|
|
|
|
}
|
2016-03-24 11:21:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@ForceInline
|
2016-05-18 18:46:14 +02:00
|
|
|
static $type$ getAndAddConvEndianWithCAS(ByteBuffer bb, int index, $type$ delta) {
|
|
|
|
$type$ nativeExpectedValue, expectedValue;
|
|
|
|
Object base = UNSAFE.getObject(bb, BYTE_BUFFER_HB);
|
|
|
|
long offset = address(bb, indexRO(bb, index));
|
|
|
|
do {
|
|
|
|
nativeExpectedValue = UNSAFE.get$RawType$Volatile(base, offset);
|
|
|
|
expectedValue = $RawBoxType$.reverseBytes(nativeExpectedValue);
|
|
|
|
} while (!UNSAFE.weakCompareAndSwap$RawType$Volatile(base, offset,
|
|
|
|
nativeExpectedValue, $RawBoxType$.reverseBytes(expectedValue + delta)));
|
|
|
|
return expectedValue;
|
|
|
|
}
|
|
|
|
|
|
|
|
@ForceInline
|
|
|
|
static $type$ addAndGet(ByteBufferHandle handle, Object obb, int index, $type$ delta) {
|
|
|
|
return getAndAdd(handle, obb, index, delta) + delta;
|
2016-03-24 11:21:21 +01:00
|
|
|
}
|
|
|
|
#end[AtomicAdd]
|
2016-05-05 11:39:08 -07:00
|
|
|
|
|
|
|
static final VarForm FORM = new VarForm(ByteBufferHandle.class, ByteBuffer.class, $type$.class, int.class);
|
2016-03-24 11:21:21 +01:00
|
|
|
}
|
|
|
|
}
|