MethodHandles.ByteArrayViewVarHandle(Class, ByteOrder) Method
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Produces a VarHandle giving access to elements of a byte[]
array
viewed as if it were a different primitive array type, such as
int[]
or long[]
.
[Android.Runtime.Register("byteArrayViewVarHandle", "(Ljava/lang/Class;Ljava/nio/ByteOrder;)Ljava/lang/invoke/VarHandle;", "", ApiSince=33)]
public static Java.Lang.Invoke.VarHandle? ByteArrayViewVarHandle (Java.Lang.Class? viewArrayClass, Java.Nio.ByteOrder? byteOrder);
[<Android.Runtime.Register("byteArrayViewVarHandle", "(Ljava/lang/Class;Ljava/nio/ByteOrder;)Ljava/lang/invoke/VarHandle;", "", ApiSince=33)>]
static member ByteArrayViewVarHandle : Java.Lang.Class * Java.Nio.ByteOrder -> Java.Lang.Invoke.VarHandle
Parameters
- viewArrayClass
- Class
the view array class, with a component type of
type T
- byteOrder
- ByteOrder
the endianness of the view array elements, as
stored in the underlying byte
array
Returns
a VarHandle giving access to elements of a byte[]
array
viewed as if elements corresponding to the components type of the view
array class
- Attributes
Remarks
Produces a VarHandle giving access to elements of a byte[]
array viewed as if it were a different primitive array type, such as int[]
or long[]
. The VarHandle's variable type is the component type of viewArrayClass
and the list of coordinate types is (byte[], int)
, where the int
coordinate type corresponds to an argument that is an index into a byte[]
array. The returned VarHandle accesses bytes at an index in a byte[]
array, composing bytes to or from a value of the component type of viewArrayClass
according to the given endianness.
The supported component types (variables types) are short
, char
, int
, long
, float
and double
.
Access of bytes at a given index will result in an IndexOutOfBoundsException
if the index is less than 0
or greater than the byte[]
array length minus the size (in bytes) of T
.
Access of bytes at an index may be aligned or misaligned for T
, with respect to the underlying memory address, A
say, associated with the array and index. If access is misaligned then access for anything other than the get
and set
access modes will result in an IllegalStateException
. In such cases atomic access is only guaranteed with respect to the largest power of two that divides the GCD of A
and the size (in bytes) of T
. If access is aligned then following access modes are supported and are guaranteed to support atomic access: <ul> <li>read write access modes for all T
, with the exception of access modes get
and set
for long
and double
on 32-bit platforms. <li>atomic update access modes for int
, long
, float
or double
. (Future major platform releases of the JDK may support additional types for certain currently unsupported access modes.) <li>numeric atomic update access modes for int
and long
. (Future major platform releases of the JDK may support additional numeric types for certain currently unsupported access modes.) <li>bitwise atomic update access modes for int
and long
. (Future major platform releases of the JDK may support additional numeric types for certain currently unsupported access modes.) </ul>
Misaligned access, and therefore atomicity guarantees, may be determined for byte[]
arrays without operating on a specific array. Given an index
, T
and it's corresponding boxed type, T_BOX
, misalignment may be determined as follows:
{@code
int sizeOfT = T_BOX.BYTES; // size in bytes of T
int misalignedAtZeroIndex = ByteBuffer.wrap(new byte[0]).
alignmentOffset(0, sizeOfT);
int misalignedAtIndex = (misalignedAtZeroIndex + index) % sizeOfT;
boolean isMisaligned = misalignedAtIndex != 0;
}
If the variable type is float
or double
then atomic update access modes compare values using their bitwise representation (see Float#floatToRawIntBits
and Double#doubleToRawLongBits
, respectively).
Added in 9.
Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.