8308276: Change layout API to work with bytes, not bits
Reviewed-by: psandoz, pminborg
This commit is contained in:
parent
91aeb5de58
commit
5fc9b5787d
@ -38,7 +38,7 @@ import java.util.Optional;
|
||||
/**
|
||||
* A value layout used to model the address of some region of memory. The carrier associated with an address layout is
|
||||
* {@code MemorySegment.class}. The size and alignment of an address layout are platform dependent
|
||||
* (e.g. on a 64-bit platform, the size and alignment of an address layout are set to 64 bits).
|
||||
* (e.g. on a 64-bit platform, the size and alignment of an address layout are set to 8 bytes).
|
||||
* <p>
|
||||
* An address layout may optionally feature a {@linkplain #targetLayout() target layout}. An address layout with
|
||||
* target layout {@code T} can be used to model the address of a region of memory whose layout is {@code T}.
|
||||
@ -74,7 +74,7 @@ public sealed interface AddressLayout extends ValueLayout permits ValueLayouts.O
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
AddressLayout withBitAlignment(long bitAlignment);
|
||||
AddressLayout withByteAlignment(long byteAlignment);
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
|
@ -68,9 +68,9 @@ public sealed interface GroupLayout extends MemoryLayout permits StructLayout, U
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
* @throws IllegalArgumentException {@inheritDoc}
|
||||
* @throws IllegalArgumentException if {@code bitAlignment} is less than {@code M}, where {@code M} is the maximum alignment
|
||||
* @throws IllegalArgumentException if {@code byteAlignment} is less than {@code M}, where {@code M} is the maximum alignment
|
||||
* constraint in any of the member layouts associated with this group layout.
|
||||
*/
|
||||
@Override
|
||||
GroupLayout withBitAlignment(long bitAlignment);
|
||||
GroupLayout withByteAlignment(long byteAlignment);
|
||||
}
|
||||
|
@ -75,7 +75,7 @@ import jdk.internal.javac.PreviewFeature;
|
||||
* SequenceLayout taggedValues = MemoryLayout.sequenceLayout(5,
|
||||
* MemoryLayout.structLayout(
|
||||
* ValueLayout.JAVA_BYTE.withName("kind"),
|
||||
* MemoryLayout.paddingLayout(24),
|
||||
* MemoryLayout.paddingLayout(3),
|
||||
* ValueLayout.JAVA_INT.withName("value")
|
||||
* )
|
||||
* ).withName("TaggedValues");
|
||||
@ -84,7 +84,7 @@ import jdk.internal.javac.PreviewFeature;
|
||||
* <h2 id="layout-align">Size, alignment and byte order</h2>
|
||||
*
|
||||
* All layouts have a size; layout size for value and padding layouts is always explicitly denoted; this means that a layout description
|
||||
* always has the same size in bits, regardless of the platform in which it is used. For derived layouts, the size is computed
|
||||
* always has the same size in bytes, regardless of the platform in which it is used. For derived layouts, the size is computed
|
||||
* as follows:
|
||||
* <ul>
|
||||
* <li>for a sequence layout <em>S</em> whose element layout is <em>E</em> and size is <em>L</em>,
|
||||
@ -104,7 +104,7 @@ import jdk.internal.javac.PreviewFeature;
|
||||
* <li>for a group layout <em>G</em> with member layouts <em>M1</em>, <em>M2</em>, ... <em>Mn</em> whose alignments are
|
||||
* <em>A1</em>, <em>A2</em>, ... <em>An</em>, respectively, the natural alignment of <em>G</em> is <em>max(A1, A2 ... An)</em></li>
|
||||
* </ul>
|
||||
* A layout's natural alignment can be overridden if needed (see {@link MemoryLayout#withBitAlignment(long)}), which can be useful to describe
|
||||
* A layout's natural alignment can be overridden if needed (see {@link MemoryLayout#withByteAlignment(long)}), which can be useful to describe
|
||||
* hyper-aligned layouts.
|
||||
* <p>
|
||||
* All value layouts have an <em>explicit</em> byte order (see {@link java.nio.ByteOrder}) which is set when the layout is created.
|
||||
@ -115,17 +115,17 @@ import jdk.internal.javac.PreviewFeature;
|
||||
* at a layout nested within the root layout - this is the layout <em>selected</em> by the layout path.
|
||||
* Layout paths are typically expressed as a sequence of one or more {@link PathElement} instances.
|
||||
* <p>
|
||||
* Layout paths are for example useful in order to obtain {@linkplain MemoryLayout#bitOffset(PathElement...) offsets} of
|
||||
* Layout paths are for example useful in order to obtain {@linkplain MemoryLayout#byteOffset(PathElement...) offsets} of
|
||||
* arbitrarily nested layouts inside another layout, to quickly obtain a {@linkplain #varHandle(PathElement...) memory access handle}
|
||||
* corresponding to the selected layout, or to {@linkplain #select(PathElement...) select} an arbitrarily nested layout inside
|
||||
* another layout.
|
||||
* <p>
|
||||
* Such <em>layout paths</em> can be constructed programmatically using the methods in this class.
|
||||
* For instance, given the {@code taggedValues} layout instance constructed as above, we can obtain the offset,
|
||||
* in bits, of the member layout named <code>value</code> in the <em>first</em> sequence element, as follows:
|
||||
* in bytes, of the member layout named <code>value</code> in the <em>first</em> sequence element, as follows:
|
||||
* {@snippet lang=java :
|
||||
* long valueOffset = taggedValues.bitOffset(PathElement.sequenceElement(0),
|
||||
* PathElement.groupElement("value")); // yields 32
|
||||
* long valueOffset = taggedValues.byteOffset(PathElement.sequenceElement(0),
|
||||
* PathElement.groupElement("value")); // yields 4
|
||||
* }
|
||||
*
|
||||
* Similarly, we can select the member layout named {@code value}, as follows:
|
||||
@ -151,7 +151,7 @@ import jdk.internal.javac.PreviewFeature;
|
||||
* access coordinate.
|
||||
*
|
||||
* <p>A layout path with free dimensions can also be used to create an offset-computing method handle, using the
|
||||
* {@link #bitOffset(PathElement...)} or {@link #byteOffsetHandle(PathElement...)} method. Again, free dimensions are
|
||||
* {@link #byteOffset(PathElement...)} or {@link #byteOffsetHandle(PathElement...)} method. Again, free dimensions are
|
||||
* translated into {@code long} parameters of the created method handle. The method handle can be used to compute the
|
||||
* offsets of elements of a sequence at different indices, by supplying these indices when invoking the method handle.
|
||||
* For instance:
|
||||
@ -172,14 +172,8 @@ import jdk.internal.javac.PreviewFeature;
|
||||
@PreviewFeature(feature=PreviewFeature.Feature.FOREIGN)
|
||||
public sealed interface MemoryLayout permits SequenceLayout, GroupLayout, PaddingLayout, ValueLayout {
|
||||
|
||||
/**
|
||||
* {@return the layout size, in bits}
|
||||
*/
|
||||
long bitSize();
|
||||
|
||||
/**
|
||||
* {@return the layout size, in bytes}
|
||||
* @throws UnsupportedOperationException if {@code bitSize()} is not a multiple of 8.
|
||||
*/
|
||||
long byteSize();
|
||||
|
||||
@ -210,24 +204,6 @@ public sealed interface MemoryLayout permits SequenceLayout, GroupLayout, Paddin
|
||||
*/
|
||||
MemoryLayout withoutName();
|
||||
|
||||
/**
|
||||
* Returns the alignment constraint associated with this layout, expressed in bits. Layout alignment defines a power
|
||||
* of two {@code A} which is the bit-wise alignment of the layout. If {@code A <= 8} then {@code A/8} is the number of
|
||||
* bytes that must be aligned for any pointer that correctly points to this layout. Thus:
|
||||
*
|
||||
* <ul>
|
||||
* <li>{@code A=8} means unaligned (in the usual sense), which is common in packets.</li>
|
||||
* <li>{@code A=64} means word aligned (on LP64), {@code A=32} int aligned, {@code A=16} short aligned, etc.</li>
|
||||
* <li>{@code A=512} is the most strict alignment required by the x86/SV ABI (for AVX-512 data).</li>
|
||||
* </ul>
|
||||
*
|
||||
* If no explicit alignment constraint was set on this layout (see {@link #withBitAlignment(long)}),
|
||||
* then this method returns the <a href="#layout-align">natural alignment</a> constraint (in bits) associated with this layout.
|
||||
*
|
||||
* @return the layout alignment constraint, in bits.
|
||||
*/
|
||||
long bitAlignment();
|
||||
|
||||
/**
|
||||
* Returns the alignment constraint associated with this layout, expressed in bytes. Layout alignment defines a power
|
||||
* of two {@code A} which is the byte-wise alignment of the layout, where {@code A} is the number of bytes that must be aligned
|
||||
@ -239,76 +215,24 @@ public sealed interface MemoryLayout permits SequenceLayout, GroupLayout, Paddin
|
||||
* <li>{@code A=64} is the most strict alignment required by the x86/SV ABI (for AVX-512 data).</li>
|
||||
* </ul>
|
||||
*
|
||||
* If no explicit alignment constraint was set on this layout (see {@link #withBitAlignment(long)}),
|
||||
* If no explicit alignment constraint was set on this layout (see {@link #withByteAlignment(long)}),
|
||||
* then this method returns the <a href="#layout-align">natural alignment</a> constraint (in bytes) associated with this layout.
|
||||
*
|
||||
* @return the layout alignment constraint, in bytes.
|
||||
* @throws UnsupportedOperationException if {@code bitAlignment()} is not a multiple of 8.
|
||||
*/
|
||||
long byteAlignment();
|
||||
|
||||
|
||||
/**
|
||||
* Returns a memory layout of the same type with the same size and name as this layout,
|
||||
* but with the specified alignment constraint (in bits).
|
||||
* but with the specified alignment constraint (in bytes).
|
||||
*
|
||||
* @param bitAlignment the layout alignment constraint, expressed in bits.
|
||||
* @param byteAlignment the layout alignment constraint, expressed in bytes.
|
||||
* @return a memory layout with the given alignment constraint.
|
||||
* @throws IllegalArgumentException if {@code bitAlignment} is not a power of two, or if it's less than 8.
|
||||
* @throws IllegalArgumentException if {@code byteAlignment} is not a power of two, or if it's less than 1.
|
||||
*/
|
||||
MemoryLayout withBitAlignment(long bitAlignment);
|
||||
MemoryLayout withByteAlignment(long byteAlignment);
|
||||
|
||||
/**
|
||||
* Computes the offset, in bits, of the layout selected by the given layout path, where the path is considered rooted in this
|
||||
* layout.
|
||||
*
|
||||
* @param elements the layout path elements.
|
||||
* @return The offset, in bits, of the layout selected by the layout path in {@code elements}.
|
||||
* @throws IllegalArgumentException if the layout path does not select any layout nested in this layout, or if the
|
||||
* layout path contains one or more path elements that select multiple sequence element indices
|
||||
* (see {@link PathElement#sequenceElement()} and {@link PathElement#sequenceElement(long, long)}).
|
||||
* @throws IllegalArgumentException if the layout path contains one or more dereference path elements
|
||||
* (see {@link PathElement#dereferenceElement()}).
|
||||
* @throws NullPointerException if either {@code elements == null}, or if any of the elements
|
||||
* in {@code elements} is {@code null}.
|
||||
*/
|
||||
default long bitOffset(PathElement... elements) {
|
||||
return computePathOp(LayoutPath.rootPath(this), LayoutPath::offset,
|
||||
EnumSet.of(PathKind.SEQUENCE_ELEMENT, PathKind.SEQUENCE_RANGE, PathKind.DEREF_ELEMENT), elements);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a method handle that can be used to compute the offset, in bits, of the layout selected
|
||||
* by the given layout path, where the path is considered rooted in this layout.
|
||||
*
|
||||
* <p>The returned method handle has a return type of {@code long}, and features as many {@code long}
|
||||
* parameter types as there are free dimensions in the provided layout path (see {@link PathElement#sequenceElement()}),
|
||||
* where the order of the parameters corresponds to the order of the path elements.
|
||||
* The returned method handle can be used to compute a layout offset similar to {@link #bitOffset(PathElement...)},
|
||||
* but where some sequence indices are specified only when invoking the method handle.
|
||||
*
|
||||
* <p>The final offset returned by the method handle is computed as follows:
|
||||
*
|
||||
* <blockquote><pre>{@code
|
||||
* offset = c_1 + c_2 + ... + c_m + (x_1 * s_1) + (x_2 * s_2) + ... + (x_n * s_n)
|
||||
* }</pre></blockquote>
|
||||
*
|
||||
* where {@code x_1}, {@code x_2}, ... {@code x_n} are <em>dynamic</em> values provided as {@code long}
|
||||
* arguments, whereas {@code c_1}, {@code c_2}, ... {@code c_m} are <em>static</em> offset constants
|
||||
* and {@code s_0}, {@code s_1}, ... {@code s_n} are <em>static</em> stride constants which are derived from
|
||||
* the layout path.
|
||||
*
|
||||
* @param elements the layout path elements.
|
||||
* @return a method handle that can be used to compute the bit offset of the layout element
|
||||
* specified by the given layout path elements, when supplied with the missing sequence element indices.
|
||||
* @throws IllegalArgumentException if the layout path contains one or more path elements that select
|
||||
* multiple sequence element indices (see {@link PathElement#sequenceElement(long, long)}).
|
||||
* @throws IllegalArgumentException if the layout path contains one or more dereference path elements
|
||||
* (see {@link PathElement#dereferenceElement()}).
|
||||
*/
|
||||
default MethodHandle bitOffsetHandle(PathElement... elements) {
|
||||
return computePathOp(LayoutPath.rootPath(this), LayoutPath::offsetHandle,
|
||||
EnumSet.of(PathKind.SEQUENCE_RANGE, PathKind.DEREF_ELEMENT), elements);
|
||||
}
|
||||
|
||||
/**
|
||||
* Computes the offset, in bytes, of the layout selected by the given layout path, where the path is considered rooted in this
|
||||
@ -321,12 +245,12 @@ public sealed interface MemoryLayout permits SequenceLayout, GroupLayout, Paddin
|
||||
* (see {@link PathElement#sequenceElement()} and {@link PathElement#sequenceElement(long, long)}).
|
||||
* @throws IllegalArgumentException if the layout path contains one or more dereference path elements
|
||||
* (see {@link PathElement#dereferenceElement()}).
|
||||
* @throws UnsupportedOperationException if {@code bitOffset(elements)} is not a multiple of 8.
|
||||
* @throws NullPointerException if either {@code elements == null}, or if any of the elements
|
||||
* in {@code elements} is {@code null}.
|
||||
*/
|
||||
default long byteOffset(PathElement... elements) {
|
||||
return Utils.bitsToBytes(bitOffset(elements));
|
||||
return computePathOp(LayoutPath.rootPath(this), LayoutPath::offset,
|
||||
EnumSet.of(PathKind.SEQUENCE_ELEMENT, PathKind.SEQUENCE_RANGE, PathKind.DEREF_ELEMENT), elements);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -342,8 +266,7 @@ public sealed interface MemoryLayout permits SequenceLayout, GroupLayout, Paddin
|
||||
* <p>The final offset returned by the method handle is computed as follows:
|
||||
*
|
||||
* <blockquote><pre>{@code
|
||||
* bitOffset = c_1 + c_2 + ... + c_m + (x_1 * s_1) + (x_2 * s_2) + ... + (x_n * s_n)
|
||||
* offset = bitOffset / 8
|
||||
* byteOffset = c_1 + c_2 + ... + c_m + (x_1 * s_1) + (x_2 * s_2) + ... + (x_n * s_n)
|
||||
* }</pre></blockquote>
|
||||
*
|
||||
* where {@code x_1}, {@code x_2}, ... {@code x_n} are <em>dynamic</em> values provided as {@code long}
|
||||
@ -351,9 +274,6 @@ public sealed interface MemoryLayout permits SequenceLayout, GroupLayout, Paddin
|
||||
* and {@code s_0}, {@code s_1}, ... {@code s_n} are <em>static</em> stride constants which are derived from
|
||||
* the layout path.
|
||||
*
|
||||
* <p>The method handle will throw an {@link UnsupportedOperationException} if the computed
|
||||
* offset in bits is not a multiple of 8.
|
||||
*
|
||||
* @param elements the layout path elements.
|
||||
* @return a method handle that can be used to compute the byte offset of the layout element
|
||||
* specified by the given layout path elements, when supplied with the missing sequence element indices.
|
||||
@ -363,9 +283,8 @@ public sealed interface MemoryLayout permits SequenceLayout, GroupLayout, Paddin
|
||||
* (see {@link PathElement#dereferenceElement()}).
|
||||
*/
|
||||
default MethodHandle byteOffsetHandle(PathElement... elements) {
|
||||
MethodHandle mh = bitOffsetHandle(elements);
|
||||
mh = MethodHandles.filterReturnValue(mh, Utils.BITS_TO_BYTES);
|
||||
return mh;
|
||||
return computePathOp(LayoutPath.rootPath(this), LayoutPath::offsetHandle,
|
||||
EnumSet.of(PathKind.SEQUENCE_RANGE, PathKind.DEREF_ELEMENT), elements);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -448,8 +367,7 @@ public sealed interface MemoryLayout permits SequenceLayout, GroupLayout, Paddin
|
||||
* <p>The offset of the returned segment is computed as follows:
|
||||
*
|
||||
* <blockquote><pre>{@code
|
||||
* bitOffset = c_1 + c_2 + ... + c_m + (x_1 * s_1) + (x_2 * s_2) + ... + (x_n * s_n)
|
||||
* offset = bitOffset / 8
|
||||
* byteOffset = c_1 + c_2 + ... + c_m + (x_1 * s_1) + (x_2 * s_2) + ... + (x_n * s_n)
|
||||
* }</pre></blockquote>
|
||||
*
|
||||
* where {@code x_1}, {@code x_2}, ... {@code x_n} are <em>dynamic</em> values provided as {@code long}
|
||||
@ -465,12 +383,8 @@ public sealed interface MemoryLayout permits SequenceLayout, GroupLayout, Paddin
|
||||
* where {@code segment} is the segment to be sliced, and where {@code layout} is the layout selected by the given
|
||||
* layout path, as per {@link MemoryLayout#select(PathElement...)}.
|
||||
*
|
||||
* <p>The method handle will throw an {@link UnsupportedOperationException} if the computed
|
||||
* offset in bits is not a multiple of 8.
|
||||
*
|
||||
* @param elements the layout path elements.
|
||||
* @return a method handle which can be used to create a slice of the selected layout element, given a segment.
|
||||
* @throws UnsupportedOperationException if the size of the selected layout in bits is not a multiple of 8.
|
||||
* @throws IllegalArgumentException if the layout path contains one or more dereference path elements
|
||||
* (see {@link PathElement#dereferenceElement()}).
|
||||
*/
|
||||
@ -687,14 +601,14 @@ public sealed interface MemoryLayout permits SequenceLayout, GroupLayout, Paddin
|
||||
String toString();
|
||||
|
||||
/**
|
||||
* Creates a padding layout with the given bitSize and a bit-alignment of eight.
|
||||
* Creates a padding layout with the given byte size and a byte-alignment of one.
|
||||
*
|
||||
* @param bitSize the padding size in bits.
|
||||
* @param byteSize the padding size (expressed in bytes).
|
||||
* @return the new selector layout.
|
||||
* @throws IllegalArgumentException if {@code bitSize <= 0} or {@code bitSize % 8 != 0}
|
||||
* @throws IllegalArgumentException if {@code byteSize <= 0}.
|
||||
*/
|
||||
static PaddingLayout paddingLayout(long bitSize) {
|
||||
return PaddingLayoutImpl.of(MemoryLayoutUtil.requireBitSizeValid(bitSize, false));
|
||||
static PaddingLayout paddingLayout(long byteSize) {
|
||||
return PaddingLayoutImpl.of(MemoryLayoutUtil.requireByteSizeValid(byteSize, false));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -704,7 +618,7 @@ public sealed interface MemoryLayout permits SequenceLayout, GroupLayout, Paddin
|
||||
* @param elementLayout the sequence element layout.
|
||||
* @return the new sequence layout with the given element layout and size.
|
||||
* @throws IllegalArgumentException if {@code elementCount } is negative.
|
||||
* @throws IllegalArgumentException if {@code elementLayout.bitSize() % elementLayout.bitAlignment() != 0}.
|
||||
* @throws IllegalArgumentException if {@code elementLayout.byteSize() % elementLayout.byteAlignment() != 0}.
|
||||
*/
|
||||
static SequenceLayout sequenceLayout(long elementCount, MemoryLayout elementLayout) {
|
||||
MemoryLayoutUtil.requireNonNegative(elementCount);
|
||||
@ -720,16 +634,16 @@ public sealed interface MemoryLayout permits SequenceLayout, GroupLayout, Paddin
|
||||
*
|
||||
* This is equivalent to the following code:
|
||||
* {@snippet lang = java:
|
||||
* sequenceLayout(Long.MAX_VALUE / elementLayout.bitSize(), elementLayout);
|
||||
* sequenceLayout(Long.MAX_VALUE / elementLayout.byteSize(), elementLayout);
|
||||
* }
|
||||
*
|
||||
* @param elementLayout the sequence element layout.
|
||||
* @return a new sequence layout with the given element layout and maximum element count.
|
||||
* @throws IllegalArgumentException if {@code elementLayout.bitSize() % elementLayout.bitAlignment() != 0}.
|
||||
* @throws IllegalArgumentException if {@code elementLayout.byteSize() % elementLayout.byteAlignment() != 0}.
|
||||
*/
|
||||
static SequenceLayout sequenceLayout(MemoryLayout elementLayout) {
|
||||
Objects.requireNonNull(elementLayout);
|
||||
return sequenceLayout(Long.MAX_VALUE / elementLayout.bitSize(), elementLayout);
|
||||
return sequenceLayout(Long.MAX_VALUE / elementLayout.byteSize(), elementLayout);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -737,7 +651,7 @@ public sealed interface MemoryLayout permits SequenceLayout, GroupLayout, Paddin
|
||||
*
|
||||
* @param elements The member layouts of the struct layout.
|
||||
* @return a struct layout with the given member layouts.
|
||||
* @throws IllegalArgumentException if the sum of the {@linkplain #bitSize() bit sizes} of the member layouts
|
||||
* @throws IllegalArgumentException if the sum of the {@linkplain #byteSize() byte sizes} of the member layouts
|
||||
* overflows.
|
||||
* @throws IllegalArgumentException if a member layout in {@code elements} occurs at an offset (relative to the start
|
||||
* of the struct layout) which is not compatible with its alignment constraint.
|
||||
@ -752,14 +666,14 @@ public sealed interface MemoryLayout permits SequenceLayout, GroupLayout, Paddin
|
||||
* To avoid the exception, clients can either insert additional padding layout elements:
|
||||
*
|
||||
* {@snippet lang = java:
|
||||
* structLayout(JAVA_SHORT, MemoryLayout.ofPadding(16), JAVA_INT)
|
||||
* structLayout(JAVA_SHORT, MemoryLayout.ofPadding(2), JAVA_INT)
|
||||
* }
|
||||
*
|
||||
* Or, alternatively, they can use a member layout which features a smaller alignment constraint. This will result
|
||||
* in a <em>packed</em> struct layout:
|
||||
*
|
||||
* {@snippet lang = java:
|
||||
* structLayout(JAVA_SHORT, JAVA_INT.withBitAlignment(16))
|
||||
* structLayout(JAVA_SHORT, JAVA_INT.withByteAlignment(2))
|
||||
* }
|
||||
*/
|
||||
static StructLayout structLayout(MemoryLayout... elements) {
|
||||
|
@ -379,7 +379,7 @@ import jdk.internal.vm.annotation.ForceInline;
|
||||
* to read a pointer from some memory segment. This can be done via the
|
||||
* {@linkplain MemorySegment#get(AddressLayout, long)} access method. This method accepts an
|
||||
* {@linkplain AddressLayout address layout} (e.g. {@link ValueLayout#ADDRESS}), the layout of the pointer
|
||||
* to be read. For instance on a 64-bit platform, the size of an address layout is 64 bits. The access operation
|
||||
* to be read. For instance on a 64-bit platform, the size of an address layout is 8 bytes. The access operation
|
||||
* also accepts an offset, expressed in bytes, which indicates the position (relative to the start of the memory segment)
|
||||
* at which the pointer is stored. The access operation returns a zero-length native memory segment, backed by a region
|
||||
* of memory whose starting address is the 64-bit value read at the specified offset.
|
||||
@ -470,7 +470,7 @@ public sealed interface MemorySegment permits AbstractMemorySegmentImpl {
|
||||
* @return the element spliterator for this segment
|
||||
* @throws IllegalArgumentException if {@code elementLayout.byteSize() == 0}.
|
||||
* @throws IllegalArgumentException if {@code byteSize() % elementLayout.byteSize() != 0}.
|
||||
* @throws IllegalArgumentException if {@code elementLayout.bitSize() % elementLayout.bitAlignment() != 0}.
|
||||
* @throws IllegalArgumentException if {@code elementLayout.byteSize() % elementLayout.byteAlignment() != 0}.
|
||||
* @throws IllegalArgumentException if this segment is <a href="MemorySegment.html#segment-alignment">incompatible
|
||||
* with the alignment constraint</a> in the provided layout.
|
||||
*/
|
||||
@ -487,7 +487,7 @@ public sealed interface MemorySegment permits AbstractMemorySegmentImpl {
|
||||
* @return a sequential {@code Stream} over disjoint slices in this segment.
|
||||
* @throws IllegalArgumentException if {@code elementLayout.byteSize() == 0}.
|
||||
* @throws IllegalArgumentException if {@code byteSize() % elementLayout.byteSize() != 0}.
|
||||
* @throws IllegalArgumentException if {@code elementLayout.bitSize() % elementLayout.bitAlignment() != 0}.
|
||||
* @throws IllegalArgumentException if {@code elementLayout.byteSize() % elementLayout.byteAlignment() != 0}.
|
||||
* @throws IllegalArgumentException if this segment is <a href="MemorySegment.html#segment-alignment">incompatible
|
||||
* with the alignment constraint</a> in the provided layout.
|
||||
*/
|
||||
|
@ -56,6 +56,5 @@ public sealed interface PaddingLayout extends MemoryLayout permits PaddingLayout
|
||||
* {@inheritDoc}
|
||||
* @throws IllegalArgumentException {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
PaddingLayout withBitAlignment(long bitAlignment);
|
||||
PaddingLayout withByteAlignment(long byteAlignment);
|
||||
}
|
||||
|
@ -143,7 +143,7 @@ public sealed interface SequenceLayout extends MemoryLayout permits SequenceLayo
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
* @throws IllegalArgumentException {@inheritDoc}
|
||||
* @throws IllegalArgumentException if {@code bitAlignment < elementLayout().bitAlignment()}.
|
||||
* @throws IllegalArgumentException if {@code byteAlignment < elementLayout().byteAlignment()}.
|
||||
*/
|
||||
SequenceLayout withBitAlignment(long bitAlignment);
|
||||
SequenceLayout withByteAlignment(long byteAlignment);
|
||||
}
|
||||
|
@ -56,5 +56,5 @@ public sealed interface StructLayout extends GroupLayout permits StructLayoutImp
|
||||
* @throws IllegalArgumentException {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
StructLayout withBitAlignment(long bitAlignment);
|
||||
StructLayout withByteAlignment(long byteAlignment);
|
||||
}
|
||||
|
@ -56,5 +56,5 @@ public sealed interface UnionLayout extends GroupLayout permits UnionLayoutImpl
|
||||
* @throws IllegalArgumentException {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
UnionLayout withBitAlignment(long bitAlignment);
|
||||
UnionLayout withByteAlignment(long byteAlignment);
|
||||
}
|
||||
|
@ -37,7 +37,7 @@ import jdk.internal.javac.PreviewFeature;
|
||||
* <em>integral</em> values (either signed or unsigned), <em>floating-point</em> values and
|
||||
* <em>address</em> values.
|
||||
* <p>
|
||||
* Each value layout has a size, an alignment (in bits),
|
||||
* Each value layout has a size, an alignment (both expressed in bytes),
|
||||
* a {@linkplain ByteOrder byte order}, and a <em>carrier</em>, that is, the Java type that should be used when
|
||||
* {@linkplain MemorySegment#get(OfInt, long) accessing} a region of memory using the value layout.
|
||||
* <p>
|
||||
@ -129,7 +129,7 @@ public sealed interface ValueLayout extends MemoryLayout permits
|
||||
* featuring {@code shape.length + 1}
|
||||
* {@code long} coordinates.
|
||||
* @throws IllegalArgumentException if {@code shape[i] < 0}, for at least one index {@code i}.
|
||||
* @throws UnsupportedOperationException if {@code bitAlignment() > bitSize()}.
|
||||
* @throws UnsupportedOperationException if {@code byteAlignment() > byteSize()}.
|
||||
* @see MethodHandles#memorySegmentViewVarHandle
|
||||
* @see MemoryLayout#varHandle(PathElement...)
|
||||
* @see SequenceLayout
|
||||
@ -152,7 +152,7 @@ public sealed interface ValueLayout extends MemoryLayout permits
|
||||
* @throws IllegalArgumentException {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
ValueLayout withBitAlignment(long bitAlignment);
|
||||
ValueLayout withByteAlignment(long byteAlignment);
|
||||
|
||||
/**
|
||||
* A value layout whose carrier is {@code boolean.class}.
|
||||
@ -180,7 +180,7 @@ public sealed interface ValueLayout extends MemoryLayout permits
|
||||
* @throws IllegalArgumentException {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
OfBoolean withBitAlignment(long bitAlignment);
|
||||
OfBoolean withByteAlignment(long byteAlignment);
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
@ -216,7 +216,7 @@ public sealed interface ValueLayout extends MemoryLayout permits
|
||||
* @throws IllegalArgumentException {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
OfByte withBitAlignment(long bitAlignment);
|
||||
OfByte withByteAlignment(long byteAlignment);
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
@ -253,7 +253,7 @@ public sealed interface ValueLayout extends MemoryLayout permits
|
||||
* @throws IllegalArgumentException {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
OfChar withBitAlignment(long bitAlignment);
|
||||
OfChar withByteAlignment(long byteAlignment);
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
@ -290,7 +290,7 @@ public sealed interface ValueLayout extends MemoryLayout permits
|
||||
* @throws IllegalArgumentException {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
OfShort withBitAlignment(long bitAlignment);
|
||||
OfShort withByteAlignment(long byteAlignment);
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
@ -327,7 +327,7 @@ public sealed interface ValueLayout extends MemoryLayout permits
|
||||
* @throws IllegalArgumentException {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
OfInt withBitAlignment(long bitAlignment);
|
||||
OfInt withByteAlignment(long byteAlignment);
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
@ -363,7 +363,7 @@ public sealed interface ValueLayout extends MemoryLayout permits
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
OfFloat withBitAlignment(long bitAlignment);
|
||||
OfFloat withByteAlignment(long byteAlignment);
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
@ -400,7 +400,7 @@ public sealed interface ValueLayout extends MemoryLayout permits
|
||||
* @throws IllegalArgumentException {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
OfLong withBitAlignment(long bitAlignment);
|
||||
OfLong withByteAlignment(long byteAlignment);
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
@ -437,7 +437,7 @@ public sealed interface ValueLayout extends MemoryLayout permits
|
||||
* @throws IllegalArgumentException {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
OfDouble withBitAlignment(long bitAlignment);
|
||||
OfDouble withByteAlignment(long byteAlignment);
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
@ -449,56 +449,56 @@ public sealed interface ValueLayout extends MemoryLayout permits
|
||||
|
||||
/**
|
||||
* A value layout constant whose size is the same as that of a machine address ({@code size_t}),
|
||||
* bit alignment set to {@code sizeof(size_t) * 8}, byte order set to {@link ByteOrder#nativeOrder()}.
|
||||
* byte alignment set to {@code sizeof(size_t)}, byte order set to {@link ByteOrder#nativeOrder()}.
|
||||
*/
|
||||
AddressLayout ADDRESS = ValueLayouts.OfAddressImpl.of(ByteOrder.nativeOrder());
|
||||
|
||||
/**
|
||||
* A value layout constant whose size is the same as that of a Java {@code byte},
|
||||
* bit alignment set to 8, and byte order set to {@link ByteOrder#nativeOrder()}.
|
||||
* byte alignment set to 1, and byte order set to {@link ByteOrder#nativeOrder()}.
|
||||
*/
|
||||
OfByte JAVA_BYTE = ValueLayouts.OfByteImpl.of(ByteOrder.nativeOrder());
|
||||
|
||||
/**
|
||||
* A value layout constant whose size is the same as that of a Java {@code boolean},
|
||||
* bit alignment set to 8, and byte order set to {@link ByteOrder#nativeOrder()}.
|
||||
* byte alignment set to 1, and byte order set to {@link ByteOrder#nativeOrder()}.
|
||||
*/
|
||||
OfBoolean JAVA_BOOLEAN = ValueLayouts.OfBooleanImpl.of(ByteOrder.nativeOrder());
|
||||
|
||||
/**
|
||||
* A value layout constant whose size is the same as that of a Java {@code char},
|
||||
* bit alignment set to 16, and byte order set to {@link ByteOrder#nativeOrder()}.
|
||||
* byte alignment set to 2, and byte order set to {@link ByteOrder#nativeOrder()}.
|
||||
*/
|
||||
OfChar JAVA_CHAR = ValueLayouts.OfCharImpl.of(ByteOrder.nativeOrder());
|
||||
|
||||
/**
|
||||
* A value layout constant whose size is the same as that of a Java {@code short},
|
||||
* bit alignment set to 16, and byte order set to {@link ByteOrder#nativeOrder()}.
|
||||
* byte alignment set to 2, and byte order set to {@link ByteOrder#nativeOrder()}.
|
||||
*/
|
||||
OfShort JAVA_SHORT = ValueLayouts.OfShortImpl.of(ByteOrder.nativeOrder());
|
||||
|
||||
/**
|
||||
* A value layout constant whose size is the same as that of a Java {@code int},
|
||||
* bit alignment set to 32, and byte order set to {@link ByteOrder#nativeOrder()}.
|
||||
* byte alignment set to 4, and byte order set to {@link ByteOrder#nativeOrder()}.
|
||||
*/
|
||||
OfInt JAVA_INT = ValueLayouts.OfIntImpl.of(ByteOrder.nativeOrder());
|
||||
|
||||
/**
|
||||
* A value layout constant whose size is the same as that of a Java {@code long},
|
||||
* (platform-dependent) bit alignment set to {@code ADDRESS.bitSize()},
|
||||
* (platform-dependent) byte alignment set to {@code ADDRESS.byteSize()},
|
||||
* and byte order set to {@link ByteOrder#nativeOrder()}.
|
||||
*/
|
||||
OfLong JAVA_LONG = ValueLayouts.OfLongImpl.of(ByteOrder.nativeOrder());
|
||||
|
||||
/**
|
||||
* A value layout constant whose size is the same as that of a Java {@code float},
|
||||
* bit alignment set to 32, and byte order set to {@link ByteOrder#nativeOrder()}.
|
||||
* byte alignment set to 4, and byte order set to {@link ByteOrder#nativeOrder()}.
|
||||
*/
|
||||
OfFloat JAVA_FLOAT = ValueLayouts.OfFloatImpl.of(ByteOrder.nativeOrder());
|
||||
|
||||
/**
|
||||
* A value layout constant whose size is the same as that of a Java {@code double},
|
||||
* (platform-dependent) bit alignment set to {@code ADDRESS.bitSize()},
|
||||
* (platform-dependent) byte alignment set to {@code ADDRESS.byteSize()},
|
||||
* and byte order set to {@link ByteOrder#nativeOrder()}.
|
||||
*/
|
||||
OfDouble JAVA_DOUBLE = ValueLayouts.OfDoubleImpl.of(ByteOrder.nativeOrder());
|
||||
@ -508,83 +508,83 @@ public sealed interface ValueLayout extends MemoryLayout permits
|
||||
* and byte order set to {@link ByteOrder#nativeOrder()}.
|
||||
* Equivalent to the following code:
|
||||
* {@snippet lang=java :
|
||||
* ADDRESS.withBitAlignment(8);
|
||||
* ADDRESS.withByteAlignment(1);
|
||||
* }
|
||||
* @apiNote Care should be taken when using unaligned value layouts as they may induce
|
||||
* performance and portability issues.
|
||||
*/
|
||||
AddressLayout ADDRESS_UNALIGNED = ADDRESS.withBitAlignment(8);
|
||||
AddressLayout ADDRESS_UNALIGNED = ADDRESS.withByteAlignment(1);
|
||||
|
||||
/**
|
||||
* An unaligned value layout constant whose size is the same as that of a Java {@code char}
|
||||
* and byte order set to {@link ByteOrder#nativeOrder()}.
|
||||
* Equivalent to the following code:
|
||||
* {@snippet lang=java :
|
||||
* JAVA_CHAR.withBitAlignment(8);
|
||||
* JAVA_CHAR.withByteAlignment(1);
|
||||
* }
|
||||
* @apiNote Care should be taken when using unaligned value layouts as they may induce
|
||||
* performance and portability issues.
|
||||
*/
|
||||
OfChar JAVA_CHAR_UNALIGNED = JAVA_CHAR.withBitAlignment(8);
|
||||
OfChar JAVA_CHAR_UNALIGNED = JAVA_CHAR.withByteAlignment(1);
|
||||
|
||||
/**
|
||||
* An unaligned value layout constant whose size is the same as that of a Java {@code short}
|
||||
* and byte order set to {@link ByteOrder#nativeOrder()}.
|
||||
* Equivalent to the following code:
|
||||
* {@snippet lang=java :
|
||||
* JAVA_SHORT.withBitAlignment(8);
|
||||
* JAVA_SHORT.withByteAlignment(1);
|
||||
* }
|
||||
* @apiNote Care should be taken when using unaligned value layouts as they may induce
|
||||
* performance and portability issues.
|
||||
*/
|
||||
OfShort JAVA_SHORT_UNALIGNED = JAVA_SHORT.withBitAlignment(8);
|
||||
OfShort JAVA_SHORT_UNALIGNED = JAVA_SHORT.withByteAlignment(1);
|
||||
|
||||
/**
|
||||
* An unaligned value layout constant whose size is the same as that of a Java {@code int}
|
||||
* and byte order set to {@link ByteOrder#nativeOrder()}.
|
||||
* Equivalent to the following code:
|
||||
* {@snippet lang=java :
|
||||
* JAVA_INT.withBitAlignment(8);
|
||||
* JAVA_INT.withByteAlignment(1);
|
||||
* }
|
||||
* @apiNote Care should be taken when using unaligned value layouts as they may induce
|
||||
* performance and portability issues.
|
||||
*/
|
||||
OfInt JAVA_INT_UNALIGNED = JAVA_INT.withBitAlignment(8);
|
||||
OfInt JAVA_INT_UNALIGNED = JAVA_INT.withByteAlignment(1);
|
||||
|
||||
/**
|
||||
* An unaligned value layout constant whose size is the same as that of a Java {@code long}
|
||||
* and byte order set to {@link ByteOrder#nativeOrder()}.
|
||||
* Equivalent to the following code:
|
||||
* {@snippet lang=java :
|
||||
* JAVA_LONG.withBitAlignment(8);
|
||||
* JAVA_LONG.withByteAlignment(1);
|
||||
* }
|
||||
* @apiNote Care should be taken when using unaligned value layouts as they may induce
|
||||
* performance and portability issues.
|
||||
*/
|
||||
OfLong JAVA_LONG_UNALIGNED = JAVA_LONG.withBitAlignment(8);
|
||||
OfLong JAVA_LONG_UNALIGNED = JAVA_LONG.withByteAlignment(1);
|
||||
|
||||
/**
|
||||
* An unaligned value layout constant whose size is the same as that of a Java {@code float}
|
||||
* and byte order set to {@link ByteOrder#nativeOrder()}.
|
||||
* Equivalent to the following code:
|
||||
* {@snippet lang=java :
|
||||
* JAVA_FLOAT.withBitAlignment(8);
|
||||
* JAVA_FLOAT.withByteAlignment(1);
|
||||
* }
|
||||
* @apiNote Care should be taken when using unaligned value layouts as they may induce
|
||||
* performance and portability issues.
|
||||
*/
|
||||
OfFloat JAVA_FLOAT_UNALIGNED = JAVA_FLOAT.withBitAlignment(8);
|
||||
OfFloat JAVA_FLOAT_UNALIGNED = JAVA_FLOAT.withByteAlignment(1);
|
||||
|
||||
/**
|
||||
* An unaligned value layout constant whose size is the same as that of a Java {@code double}
|
||||
* and byte order set to {@link ByteOrder#nativeOrder()}.
|
||||
* Equivalent to the following code:
|
||||
* {@snippet lang=java :
|
||||
* JAVA_DOUBLE.withBitAlignment(8);
|
||||
* JAVA_DOUBLE.withByteAlignment(1);
|
||||
* }
|
||||
* @apiNote Care should be taken when using unaligned value layouts as they may induce
|
||||
* performance and portability issues.
|
||||
*/
|
||||
OfDouble JAVA_DOUBLE_UNALIGNED = JAVA_DOUBLE.withBitAlignment(8);
|
||||
OfDouble JAVA_DOUBLE_UNALIGNED = JAVA_DOUBLE.withByteAlignment(1);
|
||||
|
||||
}
|
||||
|
@ -7964,7 +7964,7 @@ assertEquals("boojum", (String) catTrace.invokeExact("boo", "jum"));
|
||||
* <p>As an example, consider the memory layout expressed by a {@link GroupLayout} instance constructed as follows:
|
||||
* {@snippet lang="java" :
|
||||
* GroupLayout seq = java.lang.foreign.MemoryLayout.structLayout(
|
||||
* MemoryLayout.paddingLayout(32),
|
||||
* MemoryLayout.paddingLayout(4),
|
||||
* ValueLayout.JAVA_INT.withOrder(ByteOrder.BIG_ENDIAN).withName("value")
|
||||
* );
|
||||
* }
|
||||
|
@ -54,10 +54,10 @@ public enum CABI {
|
||||
if (ForeignLinkerSupport.isSupported()) {
|
||||
// figure out the ABI based on the platform
|
||||
String arch = StaticProperty.osArch();
|
||||
long addressSize = ADDRESS.bitSize();
|
||||
long addressSize = ADDRESS.byteSize();
|
||||
// might be running in a 32-bit VM on a 64-bit platform.
|
||||
// addressSize will be correctly 32
|
||||
if ((arch.equals("amd64") || arch.equals("x86_64")) && addressSize == 64) {
|
||||
if ((arch.equals("amd64") || arch.equals("x86_64")) && addressSize == 8) {
|
||||
if (OperatingSystem.isWindows()) {
|
||||
return WIN_64;
|
||||
} else {
|
||||
|
@ -97,7 +97,7 @@ public class LayoutPath {
|
||||
check(SequenceLayout.class, "attempting to select a sequence element from a non-sequence layout");
|
||||
SequenceLayout seq = (SequenceLayout)layout;
|
||||
MemoryLayout elem = seq.elementLayout();
|
||||
return LayoutPath.nestedPath(elem, offset, addStride(elem.bitSize()), addBound(seq.elementCount()), derefAdapters, this);
|
||||
return LayoutPath.nestedPath(elem, offset, addStride(elem.byteSize()), addBound(seq.elementCount()), derefAdapters, this);
|
||||
}
|
||||
|
||||
public LayoutPath sequenceElement(long start, long step) {
|
||||
@ -105,7 +105,7 @@ public class LayoutPath {
|
||||
SequenceLayout seq = (SequenceLayout)layout;
|
||||
checkSequenceBounds(seq, start);
|
||||
MemoryLayout elem = seq.elementLayout();
|
||||
long elemSize = elem.bitSize();
|
||||
long elemSize = elem.byteSize();
|
||||
long nelems = step > 0 ?
|
||||
seq.elementCount() - start :
|
||||
start + 1;
|
||||
@ -118,7 +118,7 @@ public class LayoutPath {
|
||||
check(SequenceLayout.class, "attempting to select a sequence element from a non-sequence layout");
|
||||
SequenceLayout seq = (SequenceLayout)layout;
|
||||
checkSequenceBounds(seq, index);
|
||||
long elemSize = seq.elementLayout().bitSize();
|
||||
long elemSize = seq.elementLayout().byteSize();
|
||||
long elemOffset = elemSize * index;
|
||||
return LayoutPath.nestedPath(seq.elementLayout(), offset + elemOffset, strides, bounds, derefAdapters,this);
|
||||
}
|
||||
@ -135,7 +135,7 @@ public class LayoutPath {
|
||||
elem = l;
|
||||
break;
|
||||
} else if (g instanceof StructLayout) {
|
||||
offset += l.bitSize();
|
||||
offset += l.byteSize();
|
||||
}
|
||||
}
|
||||
if (elem == null) {
|
||||
@ -156,7 +156,7 @@ public class LayoutPath {
|
||||
}
|
||||
elem = g.memberLayouts().get(i);
|
||||
if (g instanceof StructLayout && i < index) {
|
||||
offset += elem.bitSize();
|
||||
offset += elem.byteSize();
|
||||
}
|
||||
}
|
||||
return LayoutPath.nestedPath(elem, this.offset + offset, strides, bounds, derefAdapters, this);
|
||||
@ -196,14 +196,14 @@ public class LayoutPath {
|
||||
VarHandle handle = Utils.makeSegmentViewVarHandle(valueLayout);
|
||||
for (int i = strides.length - 1; i >= 0; i--) {
|
||||
MethodHandle collector = MethodHandles.insertArguments(MH_ADD_SCALED_OFFSET, 2,
|
||||
Utils.bitsToBytes(strides[i]),
|
||||
strides[i],
|
||||
bounds[i]);
|
||||
// (J, ...) -> J to (J, J, ...) -> J
|
||||
// i.e. new coord is prefixed. Last coord will correspond to innermost layout
|
||||
handle = MethodHandles.collectCoordinates(handle, 1, collector);
|
||||
}
|
||||
handle = MethodHandles.insertCoordinates(handle, 1,
|
||||
Utils.bitsToBytes(offset));
|
||||
offset);
|
||||
|
||||
if (adapt) {
|
||||
for (int i = derefAdapters.length; i > 0; i--) {
|
||||
@ -232,8 +232,7 @@ public class LayoutPath {
|
||||
}
|
||||
|
||||
public MethodHandle sliceHandle() {
|
||||
MethodHandle offsetHandle = offsetHandle(); // bit offset
|
||||
offsetHandle = MethodHandles.filterReturnValue(offsetHandle, Utils.BITS_TO_BYTES); // byte offset
|
||||
MethodHandle offsetHandle = offsetHandle(); // byte offset
|
||||
|
||||
MethodHandle sliceHandle = MH_SLICE; // (MS, long, long) -> MS
|
||||
sliceHandle = MethodHandles.insertArguments(sliceHandle, 2, layout.byteSize()); // (MS, long) -> MS
|
||||
|
@ -43,8 +43,8 @@ public sealed class NativeMemorySegmentImpl extends AbstractMemorySegmentImpl pe
|
||||
|
||||
private static final Unsafe UNSAFE = Unsafe.getUnsafe();
|
||||
|
||||
// The maximum alignment supported by malloc - typically 16 on
|
||||
// 64-bit platforms and 8 on 32-bit platforms.
|
||||
// The maximum alignment supported by malloc - typically 16 bytes on
|
||||
// 64-bit platforms and 8 bytes on 32-bit platforms.
|
||||
private static final long MAX_MALLOC_ALIGN = Unsafe.ADDRESS_SIZE == 4 ? 8 : 16;
|
||||
private static final boolean SKIP_ZERO_MEMORY = GetBooleanAction.privilegedGetProperty("jdk.internal.foreign.skipZeroMemory");
|
||||
|
||||
|
@ -63,7 +63,6 @@ public final class Utils {
|
||||
private static final MethodHandle BOOL_TO_BYTE;
|
||||
private static final MethodHandle ADDRESS_TO_LONG;
|
||||
private static final MethodHandle LONG_TO_ADDRESS;
|
||||
public static final MethodHandle BITS_TO_BYTES;
|
||||
|
||||
static {
|
||||
try {
|
||||
@ -76,8 +75,6 @@ public final class Utils {
|
||||
MethodType.methodType(long.class, MemorySegment.class));
|
||||
LONG_TO_ADDRESS = lookup.findStatic(Utils.class, "longToAddress",
|
||||
MethodType.methodType(MemorySegment.class, long.class, long.class, long.class));
|
||||
BITS_TO_BYTES = lookup.findStatic(Utils.class, "bitsToBytes",
|
||||
MethodType.methodType(long.class, long.class));
|
||||
} catch (Throwable ex) {
|
||||
throw new ExceptionInInitializerError(ex);
|
||||
}
|
||||
@ -92,11 +89,6 @@ public final class Utils {
|
||||
return ms.asSlice(alignUp(offset, alignment) - offset);
|
||||
}
|
||||
|
||||
public static long bitsToBytes(long bits) {
|
||||
assert Utils.isAligned(bits, 8);
|
||||
return bits / Byte.SIZE;
|
||||
}
|
||||
|
||||
public static VarHandle makeSegmentViewVarHandle(ValueLayout layout) {
|
||||
final class VarHandleCache {
|
||||
private static final Map<ValueLayout, VarHandle> HANDLE_MAP = new ConcurrentHashMap<>();
|
||||
@ -177,7 +169,7 @@ public final class Utils {
|
||||
public static void checkElementAlignment(ValueLayout layout, String msg) {
|
||||
// Fast-path: if both size and alignment are powers of two, we can just
|
||||
// check if one is greater than the other.
|
||||
assert isPowerOfTwo(layout.bitSize());
|
||||
assert isPowerOfTwo(layout.byteSize());
|
||||
if (layout.byteAlignment() > layout.byteSize()) {
|
||||
throw new IllegalArgumentException(msg);
|
||||
}
|
||||
@ -236,14 +228,14 @@ public final class Utils {
|
||||
List<MemoryLayout> layouts = new ArrayList<>();
|
||||
long align = 0;
|
||||
for (MemoryLayout l : elements) {
|
||||
long padding = computePadding(offset, l.bitAlignment());
|
||||
long padding = computePadding(offset, l.byteAlignment());
|
||||
if (padding != 0) {
|
||||
layouts.add(MemoryLayout.paddingLayout(padding));
|
||||
offset += padding;
|
||||
}
|
||||
layouts.add(l);
|
||||
align = Math.max(align, l.bitAlignment());
|
||||
offset += l.bitSize();
|
||||
align = Math.max(align, l.byteAlignment());
|
||||
offset += l.byteSize();
|
||||
}
|
||||
long padding = computePadding(offset, align);
|
||||
if (padding != 0) {
|
||||
|
@ -160,7 +160,7 @@ public abstract sealed class AbstractLinker implements Linker permits LinuxAArch
|
||||
checkMemberOffset(sl, member, lastUnpaddedOffset, offset);
|
||||
checkLayoutRecursive(member);
|
||||
|
||||
offset += member.bitSize();
|
||||
offset += member.byteSize();
|
||||
if (!(member instanceof PaddingLayout)) {
|
||||
lastUnpaddedOffset = offset;
|
||||
}
|
||||
@ -171,7 +171,7 @@ public abstract sealed class AbstractLinker implements Linker permits LinuxAArch
|
||||
for (MemoryLayout member : ul.memberLayouts()) {
|
||||
checkLayoutRecursive(member);
|
||||
if (!(member instanceof PaddingLayout)) {
|
||||
maxUnpaddedLayout = Long.max(maxUnpaddedLayout, member.bitSize());
|
||||
maxUnpaddedLayout = Long.max(maxUnpaddedLayout, member.byteSize());
|
||||
}
|
||||
}
|
||||
checkGroupSize(ul, maxUnpaddedLayout);
|
||||
@ -182,10 +182,10 @@ public abstract sealed class AbstractLinker implements Linker permits LinuxAArch
|
||||
|
||||
// check for trailing padding
|
||||
private static void checkGroupSize(GroupLayout gl, long maxUnpaddedOffset) {
|
||||
long expectedSize = Utils.alignUp(maxUnpaddedOffset, gl.bitAlignment());
|
||||
if (gl.bitSize() != expectedSize) {
|
||||
long expectedSize = Utils.alignUp(maxUnpaddedOffset, gl.byteAlignment());
|
||||
if (gl.byteSize() != expectedSize) {
|
||||
throw new IllegalArgumentException("Layout '" + gl + "' has unexpected size: "
|
||||
+ gl.bitSize() + " != " + expectedSize);
|
||||
+ gl.byteSize() + " != " + expectedSize);
|
||||
}
|
||||
}
|
||||
|
||||
@ -193,7 +193,7 @@ public abstract sealed class AbstractLinker implements Linker permits LinuxAArch
|
||||
// the previous layout
|
||||
private static void checkMemberOffset(StructLayout parent, MemoryLayout memberLayout,
|
||||
long lastUnpaddedOffset, long offset) {
|
||||
long expectedOffset = Utils.alignUp(lastUnpaddedOffset, memberLayout.bitAlignment());
|
||||
long expectedOffset = Utils.alignUp(lastUnpaddedOffset, memberLayout.byteAlignment());
|
||||
if (expectedOffset != offset) {
|
||||
throw new IllegalArgumentException("Member layout '" + memberLayout + "', of '" + parent + "'" +
|
||||
" found at unexpected offset: " + offset + " != " + expectedOffset);
|
||||
@ -202,7 +202,7 @@ public abstract sealed class AbstractLinker implements Linker permits LinuxAArch
|
||||
|
||||
private static void checkHasNaturalAlignment(MemoryLayout layout) {
|
||||
if (!((AbstractLayout<?>) layout).hasNaturalAlignment()) {
|
||||
throw new IllegalArgumentException("Layout bit alignment must be natural alignment: " + layout);
|
||||
throw new IllegalArgumentException("Layout alignment must be natural alignment: " + layout);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -79,7 +79,6 @@ public final class SharedUtils {
|
||||
public static final MethodHandle MH_CHECK_SYMBOL;
|
||||
|
||||
public static final AddressLayout C_POINTER = ADDRESS
|
||||
.withBitAlignment(64)
|
||||
.withTargetLayout(MemoryLayout.sequenceLayout(JAVA_BYTE));
|
||||
|
||||
public static final Arena DUMMY_ARENA = new Arena() {
|
||||
|
@ -58,7 +58,7 @@ public enum TypeClass {
|
||||
}
|
||||
|
||||
static boolean isRegisterAggregate(MemoryLayout type) {
|
||||
return type.bitSize() <= MAX_AGGREGATE_REGS_SIZE * 64;
|
||||
return type.byteSize() <= MAX_AGGREGATE_REGS_SIZE * 8;
|
||||
}
|
||||
|
||||
static List<MemoryLayout> scalarLayouts(GroupLayout gl) {
|
||||
@ -106,8 +106,8 @@ public enum TypeClass {
|
||||
return false;
|
||||
|
||||
TypeClass argClass = classifyValueType((ValueLayout) elem);
|
||||
if (elem.bitSize() != baseType.bitSize() ||
|
||||
elem.bitAlignment() != baseType.bitAlignment() ||
|
||||
if (elem.byteSize() != baseType.byteSize() ||
|
||||
elem.byteAlignment() != baseType.byteAlignment() ||
|
||||
baseArgClass != argClass) {
|
||||
return false;
|
||||
}
|
||||
|
@ -58,9 +58,9 @@ import static java.lang.foreign.ValueLayout.JAVA_SHORT;
|
||||
* } ffi_type;
|
||||
*/
|
||||
class FFIType {
|
||||
private static final ValueLayout SIZE_T = switch ((int) ADDRESS.bitSize()) {
|
||||
case 64 -> JAVA_LONG;
|
||||
case 32 -> JAVA_INT;
|
||||
private static final ValueLayout SIZE_T = switch ((int) ADDRESS.byteSize()) {
|
||||
case 8 -> JAVA_LONG;
|
||||
case 4 -> JAVA_INT;
|
||||
default -> throw new IllegalStateException("Address size not supported: " + ADDRESS.byteSize());
|
||||
};
|
||||
private static final ValueLayout UNSIGNED_SHORT = JAVA_SHORT;
|
||||
|
@ -181,7 +181,7 @@ public enum TypeClass {
|
||||
}
|
||||
|
||||
private static boolean isRegisterAggregate(MemoryLayout type) {
|
||||
return type.bitSize() <= MAX_AGGREGATE_REGS_SIZE * 64;
|
||||
return type.byteSize() <= MAX_AGGREGATE_REGS_SIZE * 8;
|
||||
}
|
||||
|
||||
private static TypeClass classifyStructType(GroupLayout layout) {
|
||||
|
@ -29,7 +29,6 @@ import java.lang.foreign.MemoryLayout;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
import java.util.function.LongBinaryOperator;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
@ -49,13 +48,13 @@ public sealed abstract class AbstractGroupLayout<L extends AbstractGroupLayout<L
|
||||
|
||||
private final Kind kind;
|
||||
private final List<MemoryLayout> elements;
|
||||
final long minBitAlignment;
|
||||
final long minByteAlignment;
|
||||
|
||||
AbstractGroupLayout(Kind kind, List<MemoryLayout> elements, long bitSize, long bitAlignment, long minBitAlignment, Optional<String> name) {
|
||||
super(bitSize, bitAlignment, name); // Subclassing creates toctou problems here
|
||||
AbstractGroupLayout(Kind kind, List<MemoryLayout> elements, long byteSize, long byteAlignment, long minByteAlignment, Optional<String> name) {
|
||||
super(byteSize, byteAlignment, name); // Subclassing creates toctou problems here
|
||||
this.kind = kind;
|
||||
this.elements = List.copyOf(elements);
|
||||
this.minBitAlignment = minBitAlignment;
|
||||
this.minByteAlignment = minByteAlignment;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -82,11 +81,11 @@ public sealed abstract class AbstractGroupLayout<L extends AbstractGroupLayout<L
|
||||
}
|
||||
|
||||
@Override
|
||||
public L withBitAlignment(long bitAlignment) {
|
||||
if (bitAlignment < minBitAlignment) {
|
||||
public L withByteAlignment(long byteAlignment) {
|
||||
if (byteAlignment < minByteAlignment) {
|
||||
throw new IllegalArgumentException("Invalid alignment constraint");
|
||||
}
|
||||
return super.withBitAlignment(bitAlignment);
|
||||
return super.withByteAlignment(byteAlignment);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -111,7 +110,7 @@ public sealed abstract class AbstractGroupLayout<L extends AbstractGroupLayout<L
|
||||
|
||||
@Override
|
||||
public final boolean hasNaturalAlignment() {
|
||||
return bitAlignment() == minBitAlignment;
|
||||
return byteAlignment() == minByteAlignment;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -43,30 +43,26 @@ public abstract sealed class AbstractLayout<L extends AbstractLayout<L> & Memory
|
||||
private final long byteAlignment;
|
||||
private final Optional<String> name;
|
||||
|
||||
AbstractLayout(long bitSize, long bitAlignment, Optional<String> name) {
|
||||
this.byteSize = MemoryLayoutUtil.requireBitSizeValid(bitSize, true) / 8;
|
||||
this.byteAlignment = requirePowerOfTwoAndGreaterOrEqualToEight(bitAlignment) / 8;
|
||||
AbstractLayout(long byteSize, long byteAlignment, Optional<String> name) {
|
||||
this.byteSize = MemoryLayoutUtil.requireByteSizeValid(byteSize, true);
|
||||
this.byteAlignment = requirePowerOfTwoAndGreaterOrEqualToOne(byteAlignment);
|
||||
this.name = Objects.requireNonNull(name);
|
||||
}
|
||||
|
||||
public final L withName(String name) {
|
||||
return dup(bitAlignment(), Optional.of(name));
|
||||
return dup(byteAlignment(), Optional.of(name));
|
||||
}
|
||||
|
||||
public final L withoutName() {
|
||||
return dup(bitAlignment(), Optional.empty());
|
||||
return dup(byteAlignment(), Optional.empty());
|
||||
}
|
||||
|
||||
public final Optional<String> name() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public L withBitAlignment(long bitAlignment) {
|
||||
return dup(bitAlignment, name);
|
||||
}
|
||||
|
||||
public final long bitAlignment() {
|
||||
return byteAlignment * 8;
|
||||
public L withByteAlignment(long byteAlignment) {
|
||||
return dup(byteAlignment, name);
|
||||
}
|
||||
|
||||
public final long byteAlignment() {
|
||||
@ -77,10 +73,6 @@ public abstract sealed class AbstractLayout<L extends AbstractLayout<L> & Memory
|
||||
return byteSize;
|
||||
}
|
||||
|
||||
public final long bitSize() {
|
||||
return byteSize * 8;
|
||||
}
|
||||
|
||||
public boolean hasNaturalAlignment() {
|
||||
return byteSize == byteAlignment;
|
||||
}
|
||||
@ -127,21 +119,21 @@ public abstract sealed class AbstractLayout<L extends AbstractLayout<L> & Memory
|
||||
@Override
|
||||
public abstract String toString();
|
||||
|
||||
abstract L dup(long bitAlignment, Optional<String> name);
|
||||
abstract L dup(long byteAlignment, Optional<String> name);
|
||||
|
||||
String decorateLayoutString(String s) {
|
||||
if (name().isPresent()) {
|
||||
s = String.format("%s(%s)", s, name().get());
|
||||
}
|
||||
if (!hasNaturalAlignment()) {
|
||||
s = bitAlignment() + "%" + s;
|
||||
s = byteAlignment() + "%" + s;
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
private static long requirePowerOfTwoAndGreaterOrEqualToEight(long value) {
|
||||
private static long requirePowerOfTwoAndGreaterOrEqualToOne(long value) {
|
||||
if (!Utils.isPowerOfTwo(value) || // value must be a power of two
|
||||
value < 8) { // value must be greater or equal to 8
|
||||
value < 1) { // value must be greater or equal to 1
|
||||
throw new IllegalArgumentException("Invalid alignment: " + value);
|
||||
}
|
||||
return value;
|
||||
|
@ -37,11 +37,11 @@ public final class MemoryLayoutUtil {
|
||||
return value;
|
||||
}
|
||||
|
||||
public static long requireBitSizeValid(long bitSize, boolean allowZero) {
|
||||
if ((bitSize == 0 && !allowZero) || bitSize < 0 || bitSize % 8 != 0) {
|
||||
throw new IllegalArgumentException("Invalid bitSize: " + bitSize);
|
||||
public static long requireByteSizeValid(long byteSize, boolean allowZero) {
|
||||
if ((byteSize == 0 && !allowZero) || byteSize < 0) {
|
||||
throw new IllegalArgumentException("Invalid byte size: " + byteSize);
|
||||
}
|
||||
return bitSize;
|
||||
return byteSize;
|
||||
}
|
||||
|
||||
}
|
@ -31,17 +31,17 @@ import java.util.Optional;
|
||||
|
||||
public final class PaddingLayoutImpl extends AbstractLayout<PaddingLayoutImpl> implements PaddingLayout {
|
||||
|
||||
private PaddingLayoutImpl(long bitSize) {
|
||||
this(bitSize, 8, Optional.empty());
|
||||
private PaddingLayoutImpl(long byteSize) {
|
||||
this(byteSize, 1, Optional.empty());
|
||||
}
|
||||
|
||||
private PaddingLayoutImpl(long bitSize, long bitAlignment, Optional<String> name) {
|
||||
super(bitSize, bitAlignment, name);
|
||||
private PaddingLayoutImpl(long byteSize, long byteAlignment, Optional<String> name) {
|
||||
super(byteSize, byteAlignment, name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return decorateLayoutString("x" + bitSize());
|
||||
return decorateLayoutString("x" + byteSize());
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -49,17 +49,17 @@ public final class PaddingLayoutImpl extends AbstractLayout<PaddingLayoutImpl> i
|
||||
return this == other ||
|
||||
other instanceof PaddingLayoutImpl otherPadding &&
|
||||
super.equals(other) &&
|
||||
bitSize() == otherPadding.bitSize();
|
||||
byteSize() == otherPadding.byteSize();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(super.hashCode(), bitSize());
|
||||
return Objects.hash(super.hashCode(), byteSize());
|
||||
}
|
||||
|
||||
@Override
|
||||
PaddingLayoutImpl dup(long bitAlignment, Optional<String> name) {
|
||||
return new PaddingLayoutImpl(bitSize(), bitAlignment, name);
|
||||
PaddingLayoutImpl dup(long byteAlignment, Optional<String> name) {
|
||||
return new PaddingLayoutImpl(byteSize(), byteAlignment, name);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -67,8 +67,8 @@ public final class PaddingLayoutImpl extends AbstractLayout<PaddingLayoutImpl> i
|
||||
return true;
|
||||
}
|
||||
|
||||
public static PaddingLayout of(long bitSize) {
|
||||
return new PaddingLayoutImpl(bitSize);
|
||||
public static PaddingLayout of(long byteSize) {
|
||||
return new PaddingLayoutImpl(byteSize);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -36,11 +36,11 @@ public final class SequenceLayoutImpl extends AbstractLayout<SequenceLayoutImpl>
|
||||
private final MemoryLayout elementLayout;
|
||||
|
||||
private SequenceLayoutImpl(long elemCount, MemoryLayout elementLayout) {
|
||||
this(elemCount, elementLayout, elementLayout.bitAlignment(), Optional.empty());
|
||||
this(elemCount, elementLayout, elementLayout.byteAlignment(), Optional.empty());
|
||||
}
|
||||
|
||||
private SequenceLayoutImpl(long elemCount, MemoryLayout elementLayout, long bitAlignment, Optional<String> name) {
|
||||
super(Math.multiplyExact(elemCount, elementLayout.bitSize()), bitAlignment, name);
|
||||
private SequenceLayoutImpl(long elemCount, MemoryLayout elementLayout, long byteAlignment, Optional<String> name) {
|
||||
super(Math.multiplyExact(elemCount, elementLayout.byteSize()), byteAlignment, name);
|
||||
this.elemCount = elemCount;
|
||||
this.elementLayout = elementLayout;
|
||||
}
|
||||
@ -68,7 +68,7 @@ public final class SequenceLayoutImpl extends AbstractLayout<SequenceLayoutImpl>
|
||||
* @throws IllegalArgumentException if {@code elementCount < 0}.
|
||||
*/
|
||||
public SequenceLayout withElementCount(long elementCount) {
|
||||
return new SequenceLayoutImpl(elementCount, elementLayout, bitAlignment(), name());
|
||||
return new SequenceLayoutImpl(elementCount, elementLayout, byteAlignment(), name());
|
||||
}
|
||||
|
||||
/**
|
||||
@ -176,7 +176,7 @@ public final class SequenceLayoutImpl extends AbstractLayout<SequenceLayoutImpl>
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
boolean max = (Long.MAX_VALUE / elementLayout.bitSize()) == elemCount;
|
||||
boolean max = (Long.MAX_VALUE / elementLayout.byteSize()) == elemCount;
|
||||
return decorateLayoutString(String.format("[%s:%s]",
|
||||
max ? "*" : elemCount, elementLayout));
|
||||
}
|
||||
@ -196,21 +196,21 @@ public final class SequenceLayoutImpl extends AbstractLayout<SequenceLayoutImpl>
|
||||
}
|
||||
|
||||
@Override
|
||||
SequenceLayoutImpl dup(long bitAlignment, Optional<String> name) {
|
||||
return new SequenceLayoutImpl(elementCount(), elementLayout, bitAlignment, name);
|
||||
SequenceLayoutImpl dup(long byteAlignment, Optional<String> name) {
|
||||
return new SequenceLayoutImpl(elementCount(), elementLayout, byteAlignment, name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public SequenceLayoutImpl withBitAlignment(long bitAlignment) {
|
||||
if (bitAlignment < elementLayout.bitAlignment()) {
|
||||
public SequenceLayoutImpl withByteAlignment(long byteAlignment) {
|
||||
if (byteAlignment < elementLayout.byteAlignment()) {
|
||||
throw new IllegalArgumentException("Invalid alignment constraint");
|
||||
}
|
||||
return super.withBitAlignment(bitAlignment);
|
||||
return super.withByteAlignment(byteAlignment);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasNaturalAlignment() {
|
||||
return bitAlignment() == elementLayout.bitAlignment();
|
||||
return byteAlignment() == elementLayout.byteAlignment();
|
||||
}
|
||||
|
||||
public static SequenceLayout of(long elementCount, MemoryLayout elementLayout) {
|
||||
|
@ -32,24 +32,24 @@ import java.util.Optional;
|
||||
|
||||
public final class StructLayoutImpl extends AbstractGroupLayout<StructLayoutImpl> implements StructLayout {
|
||||
|
||||
private StructLayoutImpl(List<MemoryLayout> elements, long bitSize, long bitAlignment, long minBitAlignment, Optional<String> name) {
|
||||
super(Kind.STRUCT, elements, bitSize, bitAlignment, minBitAlignment, name);
|
||||
private StructLayoutImpl(List<MemoryLayout> elements, long byteSize, long byteAlignment, long minByteAlignment, Optional<String> name) {
|
||||
super(Kind.STRUCT, elements, byteSize, byteAlignment, minByteAlignment, name);
|
||||
}
|
||||
|
||||
@Override
|
||||
StructLayoutImpl dup(long bitAlignment, Optional<String> name) {
|
||||
return new StructLayoutImpl(memberLayouts(), bitSize(), bitAlignment, minBitAlignment, name);
|
||||
StructLayoutImpl dup(long byteAlignment, Optional<String> name) {
|
||||
return new StructLayoutImpl(memberLayouts(), byteSize(), byteAlignment, minByteAlignment, name);
|
||||
}
|
||||
|
||||
public static StructLayout of(List<MemoryLayout> elements) {
|
||||
long size = 0;
|
||||
long align = 8;
|
||||
long align = 1;
|
||||
for (MemoryLayout elem : elements) {
|
||||
if (size % elem.bitAlignment() != 0) {
|
||||
if (size % elem.byteAlignment() != 0) {
|
||||
throw new IllegalArgumentException("Invalid alignment constraint for member layout: " + elem);
|
||||
}
|
||||
size = Math.addExact(size, elem.bitSize());
|
||||
align = Math.max(align, elem.bitAlignment());
|
||||
size = Math.addExact(size, elem.byteSize());
|
||||
align = Math.max(align, elem.byteAlignment());
|
||||
}
|
||||
return new StructLayoutImpl(elements, size, align, align, Optional.empty());
|
||||
}
|
||||
|
@ -32,21 +32,21 @@ import java.util.Optional;
|
||||
|
||||
public final class UnionLayoutImpl extends AbstractGroupLayout<UnionLayoutImpl> implements UnionLayout {
|
||||
|
||||
private UnionLayoutImpl(List<MemoryLayout> elements, long bitSize, long bitAlignment, long minBitAlignment, Optional<String> name) {
|
||||
super(Kind.UNION, elements, bitSize, bitAlignment, minBitAlignment, name);
|
||||
private UnionLayoutImpl(List<MemoryLayout> elements, long byteSize, long byteAlignment, long minByteAlignment, Optional<String> name) {
|
||||
super(Kind.UNION, elements, byteSize, byteAlignment, minByteAlignment, name);
|
||||
}
|
||||
|
||||
@Override
|
||||
UnionLayoutImpl dup(long bitAlignment, Optional<String> name) {
|
||||
return new UnionLayoutImpl(memberLayouts(), bitSize(), bitAlignment, minBitAlignment, name);
|
||||
UnionLayoutImpl dup(long byteAlignment, Optional<String> name) {
|
||||
return new UnionLayoutImpl(memberLayouts(), byteSize(), byteAlignment, minByteAlignment, name);
|
||||
}
|
||||
|
||||
public static UnionLayout of(List<MemoryLayout> elements) {
|
||||
long size = 0;
|
||||
long align = 8;
|
||||
long align = 1;
|
||||
for (MemoryLayout elem : elements) {
|
||||
size = Math.max(size, elem.bitSize());
|
||||
align = Math.max(align, elem.bitAlignment());
|
||||
size = Math.max(size, elem.byteSize());
|
||||
align = Math.max(align, elem.byteAlignment());
|
||||
}
|
||||
return new UnionLayoutImpl(elements, size, align, align, Optional.empty());
|
||||
}
|
||||
|
@ -46,7 +46,7 @@ import java.util.Optional;
|
||||
|
||||
/**
|
||||
* A value layout. A value layout is used to model the memory layout associated with values of basic data types, such as <em>integral</em> types
|
||||
* (either signed or unsigned) and <em>floating-point</em> types. Each value layout has a size, an alignment (in bits),
|
||||
* (either signed or unsigned) and <em>floating-point</em> types. Each value layout has a size, an alignment (expressed in bytes),
|
||||
* a {@linkplain ByteOrder byte order}, and a <em>carrier</em>, that is, the Java type that should be used when
|
||||
* {@linkplain MemorySegment#get(ValueLayout.OfInt, long) accessing} a memory region using the value layout.
|
||||
* <p>
|
||||
@ -64,18 +64,18 @@ public final class ValueLayouts {
|
||||
|
||||
abstract sealed static class AbstractValueLayout<V extends AbstractValueLayout<V> & ValueLayout> extends AbstractLayout<V> {
|
||||
|
||||
static final int ADDRESS_SIZE_BITS = Unsafe.ADDRESS_SIZE * 8;
|
||||
static final int ADDRESS_SIZE_BYTES = Unsafe.ADDRESS_SIZE;
|
||||
|
||||
private final Class<?> carrier;
|
||||
private final ByteOrder order;
|
||||
@Stable
|
||||
private VarHandle handle;
|
||||
|
||||
AbstractValueLayout(Class<?> carrier, ByteOrder order, long bitSize, long bitAlignment, Optional<String> name) {
|
||||
super(bitSize, bitAlignment, name);
|
||||
AbstractValueLayout(Class<?> carrier, ByteOrder order, long byteSize, long byteAlignment, Optional<String> name) {
|
||||
super(byteSize, byteAlignment, name);
|
||||
this.carrier = carrier;
|
||||
this.order = order;
|
||||
assertCarrierSize(carrier, bitSize);
|
||||
assertCarrierSize(carrier, byteSize);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -94,7 +94,7 @@ public final class ValueLayouts {
|
||||
*/
|
||||
public final V withOrder(ByteOrder order) {
|
||||
Objects.requireNonNull(order);
|
||||
return dup(order, bitAlignment(), name());
|
||||
return dup(order, byteAlignment(), name());
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -103,7 +103,7 @@ public final class ValueLayouts {
|
||||
if (order == ByteOrder.LITTLE_ENDIAN) {
|
||||
descriptor = Character.toLowerCase(descriptor);
|
||||
}
|
||||
return decorateLayoutString(String.format("%s%d", descriptor, bitSize()));
|
||||
return decorateLayoutString(String.format("%s%d", descriptor, byteSize()));
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -143,20 +143,21 @@ public final class ValueLayouts {
|
||||
}
|
||||
|
||||
@Override
|
||||
final V dup(long bitAlignment, Optional<String> name) {
|
||||
return dup(order(), bitAlignment, name);
|
||||
final V dup(long byteAlignment, Optional<String> name) {
|
||||
return dup(order(), byteAlignment, name);
|
||||
}
|
||||
|
||||
abstract V dup(ByteOrder order, long bitAlignment, Optional<String> name);
|
||||
abstract V dup(ByteOrder order, long byteAlignment, Optional<String> name);
|
||||
|
||||
static void assertCarrierSize(Class<?> carrier, long bitSize) {
|
||||
static void assertCarrierSize(Class<?> carrier, long byteSize) {
|
||||
assert isValidCarrier(carrier);
|
||||
assert carrier != MemorySegment.class
|
||||
// MemorySegment bitSize must always equal ADDRESS_SIZE_BITS
|
||||
|| bitSize == ADDRESS_SIZE_BITS;
|
||||
// MemorySegment byteSize must always equal ADDRESS_SIZE_BYTES
|
||||
|| byteSize == ADDRESS_SIZE_BYTES;
|
||||
assert !carrier.isPrimitive() ||
|
||||
// Primitive class bitSize must always correspond
|
||||
bitSize == (carrier == boolean.class ? 8 : Wrapper.forPrimitiveType(carrier).bitWidth());
|
||||
// Primitive class byteSize must always correspond
|
||||
byteSize == (carrier == boolean.class ? 1 :
|
||||
Utils.byteWidthOfPrimitive(carrier));
|
||||
}
|
||||
|
||||
static boolean isValidCarrier(Class<?> carrier) {
|
||||
@ -189,129 +190,129 @@ public final class ValueLayouts {
|
||||
|
||||
public static final class OfBooleanImpl extends AbstractValueLayout<OfBooleanImpl> implements ValueLayout.OfBoolean {
|
||||
|
||||
private OfBooleanImpl(ByteOrder order, long bitAlignment, Optional<String> name) {
|
||||
super(boolean.class, order, Byte.SIZE, bitAlignment, name);
|
||||
private OfBooleanImpl(ByteOrder order, long byteAlignment, Optional<String> name) {
|
||||
super(boolean.class, order, Byte.BYTES, byteAlignment, name);
|
||||
}
|
||||
|
||||
@Override
|
||||
OfBooleanImpl dup(ByteOrder order, long bitAlignment, Optional<String> name) {
|
||||
return new OfBooleanImpl(order, bitAlignment, name);
|
||||
OfBooleanImpl dup(ByteOrder order, long byteAlignment, Optional<String> name) {
|
||||
return new OfBooleanImpl(order, byteAlignment, name);
|
||||
}
|
||||
|
||||
public static OfBoolean of(ByteOrder order) {
|
||||
return new OfBooleanImpl(order, Byte.SIZE, Optional.empty());
|
||||
return new OfBooleanImpl(order, Byte.BYTES, Optional.empty());
|
||||
}
|
||||
}
|
||||
|
||||
public static final class OfByteImpl extends AbstractValueLayout<OfByteImpl> implements ValueLayout.OfByte {
|
||||
|
||||
private OfByteImpl(ByteOrder order, long bitAlignment, Optional<String> name) {
|
||||
super(byte.class, order, Byte.SIZE, bitAlignment, name);
|
||||
private OfByteImpl(ByteOrder order, long byteAlignment, Optional<String> name) {
|
||||
super(byte.class, order, Byte.BYTES, byteAlignment, name);
|
||||
}
|
||||
|
||||
@Override
|
||||
OfByteImpl dup(ByteOrder order, long bitAlignment, Optional<String> name) {
|
||||
return new OfByteImpl(order, bitAlignment, name);
|
||||
OfByteImpl dup(ByteOrder order, long byteAlignment, Optional<String> name) {
|
||||
return new OfByteImpl(order, byteAlignment, name);
|
||||
}
|
||||
|
||||
public static OfByte of(ByteOrder order) {
|
||||
return new OfByteImpl(order, Byte.SIZE, Optional.empty());
|
||||
return new OfByteImpl(order, Byte.BYTES, Optional.empty());
|
||||
}
|
||||
}
|
||||
|
||||
public static final class OfCharImpl extends AbstractValueLayout<OfCharImpl> implements ValueLayout.OfChar {
|
||||
|
||||
private OfCharImpl(ByteOrder order, long bitAlignment, Optional<String> name) {
|
||||
super(char.class, order, Character.SIZE, bitAlignment, name);
|
||||
private OfCharImpl(ByteOrder order, long byteAlignment, Optional<String> name) {
|
||||
super(char.class, order, Character.BYTES, byteAlignment, name);
|
||||
}
|
||||
|
||||
@Override
|
||||
OfCharImpl dup(ByteOrder order, long bitAlignment, Optional<String> name) {
|
||||
return new OfCharImpl(order, bitAlignment, name);
|
||||
OfCharImpl dup(ByteOrder order, long byteAlignment, Optional<String> name) {
|
||||
return new OfCharImpl(order, byteAlignment, name);
|
||||
}
|
||||
|
||||
public static OfChar of(ByteOrder order) {
|
||||
return new OfCharImpl(order, Character.SIZE, Optional.empty());
|
||||
return new OfCharImpl(order, Character.BYTES, Optional.empty());
|
||||
}
|
||||
}
|
||||
|
||||
public static final class OfShortImpl extends AbstractValueLayout<OfShortImpl> implements ValueLayout.OfShort {
|
||||
|
||||
private OfShortImpl(ByteOrder order, long bitAlignment, Optional<String> name) {
|
||||
super(short.class, order, Short.SIZE, bitAlignment, name);
|
||||
private OfShortImpl(ByteOrder order, long byteAlignment, Optional<String> name) {
|
||||
super(short.class, order, Short.BYTES, byteAlignment, name);
|
||||
}
|
||||
|
||||
@Override
|
||||
OfShortImpl dup(ByteOrder order, long bitAlignment, Optional<String> name) {
|
||||
return new OfShortImpl(order, bitAlignment, name);
|
||||
OfShortImpl dup(ByteOrder order, long byteAlignment, Optional<String> name) {
|
||||
return new OfShortImpl(order, byteAlignment, name);
|
||||
}
|
||||
|
||||
public static OfShort of(ByteOrder order) {
|
||||
return new OfShortImpl(order, Short.SIZE, Optional.empty());
|
||||
return new OfShortImpl(order, Short.BYTES, Optional.empty());
|
||||
}
|
||||
}
|
||||
|
||||
public static final class OfIntImpl extends AbstractValueLayout<OfIntImpl> implements ValueLayout.OfInt {
|
||||
|
||||
private OfIntImpl(ByteOrder order, long bitAlignment, Optional<String> name) {
|
||||
super(int.class, order, Integer.SIZE, bitAlignment, name);
|
||||
private OfIntImpl(ByteOrder order, long byteAlignment, Optional<String> name) {
|
||||
super(int.class, order, Integer.BYTES, byteAlignment, name);
|
||||
}
|
||||
|
||||
@Override
|
||||
OfIntImpl dup(ByteOrder order, long bitAlignment, Optional<String> name) {
|
||||
return new OfIntImpl(order, bitAlignment, name);
|
||||
OfIntImpl dup(ByteOrder order, long byteAlignment, Optional<String> name) {
|
||||
return new OfIntImpl(order, byteAlignment, name);
|
||||
}
|
||||
|
||||
public static OfInt of(ByteOrder order) {
|
||||
return new OfIntImpl(order, Integer.SIZE, Optional.empty());
|
||||
return new OfIntImpl(order, Integer.BYTES, Optional.empty());
|
||||
}
|
||||
}
|
||||
|
||||
public static final class OfFloatImpl extends AbstractValueLayout<OfFloatImpl> implements ValueLayout.OfFloat {
|
||||
|
||||
private OfFloatImpl(ByteOrder order, long bitAlignment, Optional<String> name) {
|
||||
super(float.class, order, Float.SIZE, bitAlignment, name);
|
||||
private OfFloatImpl(ByteOrder order, long byteAlignment, Optional<String> name) {
|
||||
super(float.class, order, Float.BYTES, byteAlignment, name);
|
||||
}
|
||||
|
||||
@Override
|
||||
OfFloatImpl dup(ByteOrder order, long bitAlignment, Optional<String> name) {
|
||||
return new OfFloatImpl(order, bitAlignment, name);
|
||||
OfFloatImpl dup(ByteOrder order, long byteAlignment, Optional<String> name) {
|
||||
return new OfFloatImpl(order, byteAlignment, name);
|
||||
}
|
||||
|
||||
public static OfFloat of(ByteOrder order) {
|
||||
return new OfFloatImpl(order, Float.SIZE, Optional.empty());
|
||||
return new OfFloatImpl(order, Float.BYTES, Optional.empty());
|
||||
}
|
||||
}
|
||||
|
||||
public static final class OfLongImpl extends AbstractValueLayout<OfLongImpl> implements ValueLayout.OfLong {
|
||||
|
||||
private OfLongImpl(ByteOrder order, long bitAlignment, Optional<String> name) {
|
||||
super(long.class, order, Long.SIZE, bitAlignment, name);
|
||||
private OfLongImpl(ByteOrder order, long byteAlignment, Optional<String> name) {
|
||||
super(long.class, order, Long.BYTES, byteAlignment, name);
|
||||
}
|
||||
|
||||
@Override
|
||||
OfLongImpl dup(ByteOrder order, long bitAlignment, Optional<String> name) {
|
||||
return new OfLongImpl(order, bitAlignment, name);
|
||||
OfLongImpl dup(ByteOrder order, long byteAlignment, Optional<String> name) {
|
||||
return new OfLongImpl(order, byteAlignment, name);
|
||||
}
|
||||
|
||||
public static OfLong of(ByteOrder order) {
|
||||
return new OfLongImpl(order, ADDRESS_SIZE_BITS, Optional.empty());
|
||||
return new OfLongImpl(order, ADDRESS_SIZE_BYTES, Optional.empty());
|
||||
}
|
||||
}
|
||||
|
||||
public static final class OfDoubleImpl extends AbstractValueLayout<OfDoubleImpl> implements ValueLayout.OfDouble {
|
||||
|
||||
private OfDoubleImpl(ByteOrder order, long bitAlignment, Optional<String> name) {
|
||||
super(double.class, order, Double.SIZE, bitAlignment, name);
|
||||
private OfDoubleImpl(ByteOrder order, long byteAlignment, Optional<String> name) {
|
||||
super(double.class, order, Double.BYTES, byteAlignment, name);
|
||||
}
|
||||
|
||||
@Override
|
||||
OfDoubleImpl dup(ByteOrder order, long bitAlignment, Optional<String> name) {
|
||||
return new OfDoubleImpl(order, bitAlignment, name);
|
||||
OfDoubleImpl dup(ByteOrder order, long byteAlignment, Optional<String> name) {
|
||||
return new OfDoubleImpl(order, byteAlignment, name);
|
||||
}
|
||||
|
||||
public static OfDouble of(ByteOrder order) {
|
||||
return new OfDoubleImpl(order, ADDRESS_SIZE_BITS, Optional.empty());
|
||||
return new OfDoubleImpl(order, ADDRESS_SIZE_BYTES, Optional.empty());
|
||||
}
|
||||
|
||||
}
|
||||
@ -320,14 +321,14 @@ public final class ValueLayouts {
|
||||
|
||||
private final MemoryLayout targetLayout;
|
||||
|
||||
private OfAddressImpl(ByteOrder order, long bitSize, long bitAlignment, MemoryLayout targetLayout, Optional<String> name) {
|
||||
super(MemorySegment.class, order, bitSize, bitAlignment, name);
|
||||
private OfAddressImpl(ByteOrder order, long byteSize, long byteAlignment, MemoryLayout targetLayout, Optional<String> name) {
|
||||
super(MemorySegment.class, order, byteSize, byteAlignment, name);
|
||||
this.targetLayout = targetLayout;
|
||||
}
|
||||
|
||||
@Override
|
||||
OfAddressImpl dup(ByteOrder order, long bitAlignment, Optional<String> name) {
|
||||
return new OfAddressImpl(order, bitSize(), bitAlignment,targetLayout, name);
|
||||
OfAddressImpl dup(ByteOrder order, long byteAlignment, Optional<String> name) {
|
||||
return new OfAddressImpl(order, byteSize(), byteAlignment,targetLayout, name);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -346,12 +347,12 @@ public final class ValueLayouts {
|
||||
public AddressLayout withTargetLayout(MemoryLayout layout) {
|
||||
Reflection.ensureNativeAccess(Reflection.getCallerClass(), AddressLayout.class, "withTargetLayout");
|
||||
Objects.requireNonNull(layout);
|
||||
return new OfAddressImpl(order(), bitSize(), bitAlignment(), layout, name());
|
||||
return new OfAddressImpl(order(), byteSize(), byteAlignment(), layout, name());
|
||||
}
|
||||
|
||||
@Override
|
||||
public AddressLayout withoutTargetLayout() {
|
||||
return new OfAddressImpl(order(), bitSize(), bitAlignment(), null, name());
|
||||
return new OfAddressImpl(order(), byteSize(), byteAlignment(), null, name());
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -360,7 +361,7 @@ public final class ValueLayouts {
|
||||
}
|
||||
|
||||
public static AddressLayout of(ByteOrder order) {
|
||||
return new OfAddressImpl(order, ADDRESS_SIZE_BITS, ADDRESS_SIZE_BITS, null, Optional.empty());
|
||||
return new OfAddressImpl(order, ADDRESS_SIZE_BYTES, ADDRESS_SIZE_BYTES, null, Optional.empty());
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -369,7 +370,7 @@ public final class ValueLayouts {
|
||||
if (order() == ByteOrder.LITTLE_ENDIAN) {
|
||||
descriptor = Character.toLowerCase(descriptor);
|
||||
}
|
||||
String str = decorateLayoutString(String.format("%s%d", descriptor, bitSize()));
|
||||
String str = decorateLayoutString(String.format("%s%d", descriptor, byteSize()));
|
||||
if (targetLayout != null) {
|
||||
str += ":" + targetLayout;
|
||||
}
|
||||
|
@ -57,7 +57,7 @@ public abstract class ByteVector extends AbstractVector<Byte> {
|
||||
|
||||
static final int FORBID_OPCODE_KIND = VO_ONLYFP;
|
||||
|
||||
static final ValueLayout.OfByte ELEMENT_LAYOUT = ValueLayout.JAVA_BYTE.withBitAlignment(8);
|
||||
static final ValueLayout.OfByte ELEMENT_LAYOUT = ValueLayout.JAVA_BYTE.withByteAlignment(1);
|
||||
|
||||
@ForceInline
|
||||
static int opCode(Operator op) {
|
||||
@ -3302,7 +3302,7 @@ public abstract class ByteVector extends AbstractVector<Byte> {
|
||||
* byte[] ar = new byte[species.length()];
|
||||
* for (int n = 0; n < ar.length; n++) {
|
||||
* if (m.laneIsSet(n)) {
|
||||
* ar[n] = slice.getAtIndex(ValuaLayout.JAVA_BYTE.withBitAlignment(8), n);
|
||||
* ar[n] = slice.getAtIndex(ValuaLayout.JAVA_BYTE.withByteAlignment(1), n);
|
||||
* }
|
||||
* }
|
||||
* ByteVector r = ByteVector.fromArray(species, ar, 0);
|
||||
|
@ -57,7 +57,7 @@ public abstract class DoubleVector extends AbstractVector<Double> {
|
||||
|
||||
static final int FORBID_OPCODE_KIND = VO_NOFP;
|
||||
|
||||
static final ValueLayout.OfDouble ELEMENT_LAYOUT = ValueLayout.JAVA_DOUBLE.withBitAlignment(8);
|
||||
static final ValueLayout.OfDouble ELEMENT_LAYOUT = ValueLayout.JAVA_DOUBLE.withByteAlignment(1);
|
||||
|
||||
@ForceInline
|
||||
static int opCode(Operator op) {
|
||||
@ -2985,7 +2985,7 @@ public abstract class DoubleVector extends AbstractVector<Double> {
|
||||
* double[] ar = new double[species.length()];
|
||||
* for (int n = 0; n < ar.length; n++) {
|
||||
* if (m.laneIsSet(n)) {
|
||||
* ar[n] = slice.getAtIndex(ValuaLayout.JAVA_DOUBLE.withBitAlignment(8), n);
|
||||
* ar[n] = slice.getAtIndex(ValuaLayout.JAVA_DOUBLE.withByteAlignment(1), n);
|
||||
* }
|
||||
* }
|
||||
* DoubleVector r = DoubleVector.fromArray(species, ar, 0);
|
||||
|
@ -57,7 +57,7 @@ public abstract class FloatVector extends AbstractVector<Float> {
|
||||
|
||||
static final int FORBID_OPCODE_KIND = VO_NOFP;
|
||||
|
||||
static final ValueLayout.OfFloat ELEMENT_LAYOUT = ValueLayout.JAVA_FLOAT.withBitAlignment(8);
|
||||
static final ValueLayout.OfFloat ELEMENT_LAYOUT = ValueLayout.JAVA_FLOAT.withByteAlignment(1);
|
||||
|
||||
@ForceInline
|
||||
static int opCode(Operator op) {
|
||||
@ -2991,7 +2991,7 @@ public abstract class FloatVector extends AbstractVector<Float> {
|
||||
* float[] ar = new float[species.length()];
|
||||
* for (int n = 0; n < ar.length; n++) {
|
||||
* if (m.laneIsSet(n)) {
|
||||
* ar[n] = slice.getAtIndex(ValuaLayout.JAVA_FLOAT.withBitAlignment(8), n);
|
||||
* ar[n] = slice.getAtIndex(ValuaLayout.JAVA_FLOAT.withByteAlignment(1), n);
|
||||
* }
|
||||
* }
|
||||
* FloatVector r = FloatVector.fromArray(species, ar, 0);
|
||||
|
@ -57,7 +57,7 @@ public abstract class IntVector extends AbstractVector<Integer> {
|
||||
|
||||
static final int FORBID_OPCODE_KIND = VO_ONLYFP;
|
||||
|
||||
static final ValueLayout.OfInt ELEMENT_LAYOUT = ValueLayout.JAVA_INT.withBitAlignment(8);
|
||||
static final ValueLayout.OfInt ELEMENT_LAYOUT = ValueLayout.JAVA_INT.withByteAlignment(1);
|
||||
|
||||
@ForceInline
|
||||
static int opCode(Operator op) {
|
||||
@ -3147,7 +3147,7 @@ public abstract class IntVector extends AbstractVector<Integer> {
|
||||
* int[] ar = new int[species.length()];
|
||||
* for (int n = 0; n < ar.length; n++) {
|
||||
* if (m.laneIsSet(n)) {
|
||||
* ar[n] = slice.getAtIndex(ValuaLayout.JAVA_INT.withBitAlignment(8), n);
|
||||
* ar[n] = slice.getAtIndex(ValuaLayout.JAVA_INT.withByteAlignment(1), n);
|
||||
* }
|
||||
* }
|
||||
* IntVector r = IntVector.fromArray(species, ar, 0);
|
||||
|
@ -57,7 +57,7 @@ public abstract class LongVector extends AbstractVector<Long> {
|
||||
|
||||
static final int FORBID_OPCODE_KIND = VO_ONLYFP;
|
||||
|
||||
static final ValueLayout.OfLong ELEMENT_LAYOUT = ValueLayout.JAVA_LONG.withBitAlignment(8);
|
||||
static final ValueLayout.OfLong ELEMENT_LAYOUT = ValueLayout.JAVA_LONG.withByteAlignment(1);
|
||||
|
||||
@ForceInline
|
||||
static int opCode(Operator op) {
|
||||
@ -3026,7 +3026,7 @@ public abstract class LongVector extends AbstractVector<Long> {
|
||||
* long[] ar = new long[species.length()];
|
||||
* for (int n = 0; n < ar.length; n++) {
|
||||
* if (m.laneIsSet(n)) {
|
||||
* ar[n] = slice.getAtIndex(ValuaLayout.JAVA_LONG.withBitAlignment(8), n);
|
||||
* ar[n] = slice.getAtIndex(ValuaLayout.JAVA_LONG.withByteAlignment(1), n);
|
||||
* }
|
||||
* }
|
||||
* LongVector r = LongVector.fromArray(species, ar, 0);
|
||||
|
@ -57,7 +57,7 @@ public abstract class ShortVector extends AbstractVector<Short> {
|
||||
|
||||
static final int FORBID_OPCODE_KIND = VO_ONLYFP;
|
||||
|
||||
static final ValueLayout.OfShort ELEMENT_LAYOUT = ValueLayout.JAVA_SHORT.withBitAlignment(8);
|
||||
static final ValueLayout.OfShort ELEMENT_LAYOUT = ValueLayout.JAVA_SHORT.withByteAlignment(1);
|
||||
|
||||
@ForceInline
|
||||
static int opCode(Operator op) {
|
||||
@ -3296,7 +3296,7 @@ public abstract class ShortVector extends AbstractVector<Short> {
|
||||
* short[] ar = new short[species.length()];
|
||||
* for (int n = 0; n < ar.length; n++) {
|
||||
* if (m.laneIsSet(n)) {
|
||||
* ar[n] = slice.getAtIndex(ValuaLayout.JAVA_SHORT.withBitAlignment(8), n);
|
||||
* ar[n] = slice.getAtIndex(ValuaLayout.JAVA_SHORT.withByteAlignment(1), n);
|
||||
* }
|
||||
* }
|
||||
* ShortVector r = ShortVector.fromArray(species, ar, 0);
|
||||
|
@ -61,7 +61,7 @@ public abstract class $abstractvectortype$ extends AbstractVector<$Boxtype$> {
|
||||
static final int FORBID_OPCODE_KIND = VO_ONLYFP;
|
||||
#end[FP]
|
||||
|
||||
static final ValueLayout.Of$Type$ ELEMENT_LAYOUT = ValueLayout.JAVA_$TYPE$.withBitAlignment(8);
|
||||
static final ValueLayout.Of$Type$ ELEMENT_LAYOUT = ValueLayout.JAVA_$TYPE$.withByteAlignment(1);
|
||||
|
||||
@ForceInline
|
||||
static int opCode(Operator op) {
|
||||
@ -4098,7 +4098,7 @@ public abstract class $abstractvectortype$ extends AbstractVector<$Boxtype$> {
|
||||
* $type$[] ar = new $type$[species.length()];
|
||||
* for (int n = 0; n < ar.length; n++) {
|
||||
* if (m.laneIsSet(n)) {
|
||||
* ar[n] = slice.getAtIndex(ValuaLayout.JAVA_$TYPE$.withBitAlignment(8), n);
|
||||
* ar[n] = slice.getAtIndex(ValuaLayout.JAVA_$TYPE$.withByteAlignment(1), n);
|
||||
* }
|
||||
* }
|
||||
* $abstractvectortype$ r = $abstractvectortype$.fromArray(species, ar, 0);
|
||||
|
@ -41,7 +41,7 @@ public class MemoryLayoutTypeRetentionTest {
|
||||
// withName() et al. should return the same type as the original object.
|
||||
|
||||
private static final String NAME = "a";
|
||||
private static final long BIT_ALIGNMENT = Byte.SIZE;
|
||||
private static final long BYTE_ALIGNMENT = Byte.BYTES;
|
||||
private static final ByteOrder BYTE_ORDER = ByteOrder.nativeOrder() == ByteOrder.BIG_ENDIAN
|
||||
? ByteOrder.LITTLE_ENDIAN
|
||||
: ByteOrder.BIG_ENDIAN;
|
||||
@ -49,7 +49,7 @@ public class MemoryLayoutTypeRetentionTest {
|
||||
@Test
|
||||
public void testOfBoolean() {
|
||||
OfBoolean v = JAVA_BOOLEAN
|
||||
.withBitAlignment(BIT_ALIGNMENT)
|
||||
.withByteAlignment(BYTE_ALIGNMENT)
|
||||
.withoutName()
|
||||
.withName(NAME)
|
||||
.withOrder(BYTE_ORDER);
|
||||
@ -59,7 +59,7 @@ public class MemoryLayoutTypeRetentionTest {
|
||||
@Test
|
||||
public void testOfByte() {
|
||||
OfByte v = JAVA_BYTE
|
||||
.withBitAlignment(BIT_ALIGNMENT)
|
||||
.withByteAlignment(BYTE_ALIGNMENT)
|
||||
.withoutName()
|
||||
.withName(NAME)
|
||||
.withOrder(BYTE_ORDER);
|
||||
@ -69,7 +69,7 @@ public class MemoryLayoutTypeRetentionTest {
|
||||
@Test
|
||||
public void testOfShort() {
|
||||
OfShort v = JAVA_SHORT
|
||||
.withBitAlignment(BIT_ALIGNMENT)
|
||||
.withByteAlignment(BYTE_ALIGNMENT)
|
||||
.withoutName()
|
||||
.withName(NAME)
|
||||
.withOrder(BYTE_ORDER);
|
||||
@ -79,7 +79,7 @@ public class MemoryLayoutTypeRetentionTest {
|
||||
@Test
|
||||
public void testOfInt() {
|
||||
OfInt v = JAVA_INT
|
||||
.withBitAlignment(BIT_ALIGNMENT)
|
||||
.withByteAlignment(BYTE_ALIGNMENT)
|
||||
.withoutName()
|
||||
.withName(NAME)
|
||||
.withOrder(BYTE_ORDER);
|
||||
@ -89,7 +89,7 @@ public class MemoryLayoutTypeRetentionTest {
|
||||
@Test
|
||||
public void testOfChar() {
|
||||
OfChar v = JAVA_CHAR
|
||||
.withBitAlignment(BIT_ALIGNMENT)
|
||||
.withByteAlignment(BYTE_ALIGNMENT)
|
||||
.withoutName()
|
||||
.withName(NAME)
|
||||
.withOrder(BYTE_ORDER);
|
||||
@ -99,7 +99,7 @@ public class MemoryLayoutTypeRetentionTest {
|
||||
@Test
|
||||
public void testOfLong() {
|
||||
OfLong v = JAVA_LONG
|
||||
.withBitAlignment(BIT_ALIGNMENT)
|
||||
.withByteAlignment(BYTE_ALIGNMENT)
|
||||
.withoutName()
|
||||
.withName(NAME)
|
||||
.withOrder(BYTE_ORDER);
|
||||
@ -109,7 +109,7 @@ public class MemoryLayoutTypeRetentionTest {
|
||||
@Test
|
||||
public void testOfFloat() {
|
||||
OfFloat v = JAVA_FLOAT
|
||||
.withBitAlignment(BIT_ALIGNMENT)
|
||||
.withByteAlignment(BYTE_ALIGNMENT)
|
||||
.withoutName()
|
||||
.withName(NAME)
|
||||
.withOrder(BYTE_ORDER);
|
||||
@ -119,7 +119,7 @@ public class MemoryLayoutTypeRetentionTest {
|
||||
@Test
|
||||
public void testOfDouble() {
|
||||
OfDouble v = JAVA_DOUBLE
|
||||
.withBitAlignment(BIT_ALIGNMENT)
|
||||
.withByteAlignment(BYTE_ALIGNMENT)
|
||||
.withoutName()
|
||||
.withName(NAME)
|
||||
.withOrder(BYTE_ORDER);
|
||||
@ -129,7 +129,7 @@ public class MemoryLayoutTypeRetentionTest {
|
||||
@Test
|
||||
public void testValueLayout() {
|
||||
ValueLayout v = ((ValueLayout) JAVA_INT)
|
||||
.withBitAlignment(BIT_ALIGNMENT)
|
||||
.withByteAlignment(BYTE_ALIGNMENT)
|
||||
.withoutName()
|
||||
.withName(NAME)
|
||||
.withOrder(BYTE_ORDER);
|
||||
@ -139,7 +139,7 @@ public class MemoryLayoutTypeRetentionTest {
|
||||
@Test
|
||||
public void testAddressLayout() {
|
||||
AddressLayout v = ADDRESS
|
||||
.withBitAlignment(BIT_ALIGNMENT)
|
||||
.withByteAlignment(BYTE_ALIGNMENT)
|
||||
.withoutName()
|
||||
.withName(NAME)
|
||||
.withoutTargetLayout()
|
||||
@ -156,8 +156,8 @@ public class MemoryLayoutTypeRetentionTest {
|
||||
|
||||
@Test
|
||||
public void testPaddingLayout() {
|
||||
PaddingLayout v = MemoryLayout.paddingLayout(8)
|
||||
.withBitAlignment(BIT_ALIGNMENT)
|
||||
PaddingLayout v = MemoryLayout.paddingLayout(1)
|
||||
.withByteAlignment(BYTE_ALIGNMENT)
|
||||
.withoutName()
|
||||
.withName(NAME);
|
||||
check(v);
|
||||
@ -166,9 +166,9 @@ public class MemoryLayoutTypeRetentionTest {
|
||||
@Test
|
||||
public void testGroupLayout() {
|
||||
GroupLayout v = MemoryLayout.structLayout(
|
||||
JAVA_INT.withBitAlignment(BIT_ALIGNMENT),
|
||||
JAVA_LONG.withBitAlignment(BIT_ALIGNMENT))
|
||||
.withBitAlignment(BIT_ALIGNMENT)
|
||||
JAVA_INT.withByteAlignment(BYTE_ALIGNMENT),
|
||||
JAVA_LONG.withByteAlignment(BYTE_ALIGNMENT))
|
||||
.withByteAlignment(BYTE_ALIGNMENT)
|
||||
.withoutName()
|
||||
.withName(NAME);
|
||||
check(v);
|
||||
@ -177,9 +177,9 @@ public class MemoryLayoutTypeRetentionTest {
|
||||
@Test
|
||||
public void testStructLayout() {
|
||||
StructLayout v = MemoryLayout.structLayout(
|
||||
JAVA_INT.withBitAlignment(BIT_ALIGNMENT),
|
||||
JAVA_LONG.withBitAlignment(BIT_ALIGNMENT))
|
||||
.withBitAlignment(BIT_ALIGNMENT)
|
||||
JAVA_INT.withByteAlignment(BYTE_ALIGNMENT),
|
||||
JAVA_LONG.withByteAlignment(BYTE_ALIGNMENT))
|
||||
.withByteAlignment(BYTE_ALIGNMENT)
|
||||
.withoutName()
|
||||
.withName(NAME);
|
||||
check(v);
|
||||
@ -188,9 +188,9 @@ public class MemoryLayoutTypeRetentionTest {
|
||||
@Test
|
||||
public void testUnionLayout() {
|
||||
UnionLayout v = MemoryLayout.unionLayout(
|
||||
JAVA_INT.withBitAlignment(BIT_ALIGNMENT),
|
||||
JAVA_LONG.withBitAlignment(BIT_ALIGNMENT))
|
||||
.withBitAlignment(BIT_ALIGNMENT)
|
||||
JAVA_INT.withByteAlignment(BYTE_ALIGNMENT),
|
||||
JAVA_LONG.withByteAlignment(BYTE_ALIGNMENT))
|
||||
.withByteAlignment(BYTE_ALIGNMENT)
|
||||
.withoutName()
|
||||
.withName(NAME);
|
||||
check(v);
|
||||
@ -206,8 +206,7 @@ public class MemoryLayoutTypeRetentionTest {
|
||||
assertEquals(v.name().orElseThrow(), NAME);
|
||||
assertTrue(v.withoutName().name().isEmpty());
|
||||
|
||||
assertEquals(v.bitAlignment(), BIT_ALIGNMENT);
|
||||
assertEquals(v.byteSize() * 8, v.bitSize());
|
||||
assertEquals(v.byteAlignment(), BYTE_ALIGNMENT);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -100,28 +100,28 @@ public class NativeTestHelper {
|
||||
/**
|
||||
* The layout for the {@code short} C type
|
||||
*/
|
||||
public static final ValueLayout.OfShort C_SHORT = ValueLayout.JAVA_SHORT.withBitAlignment(16);
|
||||
public static final ValueLayout.OfShort C_SHORT = ValueLayout.JAVA_SHORT;
|
||||
/**
|
||||
* The layout for the {@code int} C type
|
||||
*/
|
||||
public static final ValueLayout.OfInt C_INT = ValueLayout.JAVA_INT.withBitAlignment(32);
|
||||
public static final ValueLayout.OfInt C_INT = ValueLayout.JAVA_INT;
|
||||
|
||||
/**
|
||||
* The layout for the {@code long long} C type.
|
||||
*/
|
||||
public static final ValueLayout.OfLong C_LONG_LONG = ValueLayout.JAVA_LONG.withBitAlignment(64);
|
||||
public static final ValueLayout.OfLong C_LONG_LONG = ValueLayout.JAVA_LONG;
|
||||
/**
|
||||
* The layout for the {@code float} C type
|
||||
*/
|
||||
public static final ValueLayout.OfFloat C_FLOAT = ValueLayout.JAVA_FLOAT.withBitAlignment(32);
|
||||
public static final ValueLayout.OfFloat C_FLOAT = ValueLayout.JAVA_FLOAT;
|
||||
/**
|
||||
* The layout for the {@code double} C type
|
||||
*/
|
||||
public static final ValueLayout.OfDouble C_DOUBLE = ValueLayout.JAVA_DOUBLE.withBitAlignment(64);
|
||||
public static final ValueLayout.OfDouble C_DOUBLE = ValueLayout.JAVA_DOUBLE;
|
||||
/**
|
||||
* The {@code T*} native type.
|
||||
*/
|
||||
public static final AddressLayout C_POINTER = ValueLayout.ADDRESS.withBitAlignment(64)
|
||||
public static final AddressLayout C_POINTER = ValueLayout.ADDRESS
|
||||
.withTargetLayout(MemoryLayout.sequenceLayout(C_CHAR));
|
||||
|
||||
public static final Linker LINKER = Linker.nativeLinker();
|
||||
|
@ -233,7 +233,7 @@ public class StdLibTest extends NativeTestHelper {
|
||||
C_INT.withName("wday"),
|
||||
C_INT.withName("yday"),
|
||||
C_BOOL.withName("isdst"),
|
||||
MemoryLayout.paddingLayout(24)
|
||||
MemoryLayout.paddingLayout(3)
|
||||
);
|
||||
|
||||
Tm(MemorySegment addr) {
|
||||
|
@ -254,13 +254,13 @@ public class TestArrayCopy {
|
||||
@Test(expectedExceptions = IllegalArgumentException.class)
|
||||
public void testHyperAlignedSrc() {
|
||||
MemorySegment segment = MemorySegment.ofArray(new byte[] {1, 2, 3, 4});
|
||||
MemorySegment.copy(new byte[] { 1, 2, 3, 4 }, 0, segment, JAVA_BYTE.withBitAlignment(16), 0, 4);
|
||||
MemorySegment.copy(new byte[] { 1, 2, 3, 4 }, 0, segment, JAVA_BYTE.withByteAlignment(2), 0, 4);
|
||||
}
|
||||
|
||||
@Test(expectedExceptions = IllegalArgumentException.class)
|
||||
public void testHyperAlignedDst() {
|
||||
MemorySegment segment = MemorySegment.ofArray(new byte[] {1, 2, 3, 4});
|
||||
MemorySegment.copy(segment, JAVA_BYTE.withBitAlignment(16), 0, new byte[] { 1, 2, 3, 4 }, 0, 4);
|
||||
MemorySegment.copy(segment, JAVA_BYTE.withByteAlignment(2), 0, new byte[] { 1, 2, 3, 4 }, 0, 4);
|
||||
}
|
||||
|
||||
/***** Utilities *****/
|
||||
@ -328,7 +328,7 @@ public class TestArrayCopy {
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public CopyHelper(L elementLayout, Class<X> carrier) {
|
||||
this.elementLayout = (L)elementLayout.withBitAlignment(8);
|
||||
this.elementLayout = (L)elementLayout.withByteAlignment(1);
|
||||
this.carrier = carrier;
|
||||
}
|
||||
|
||||
|
@ -77,13 +77,7 @@ import org.testng.SkipException;
|
||||
import org.testng.annotations.*;
|
||||
import sun.nio.ch.DirectBuffer;
|
||||
|
||||
import static java.lang.foreign.ValueLayout.JAVA_BYTE;
|
||||
import static java.lang.foreign.ValueLayout.JAVA_CHAR;
|
||||
import static java.lang.foreign.ValueLayout.JAVA_DOUBLE;
|
||||
import static java.lang.foreign.ValueLayout.JAVA_FLOAT;
|
||||
import static java.lang.foreign.ValueLayout.JAVA_INT;
|
||||
import static java.lang.foreign.ValueLayout.JAVA_LONG;
|
||||
import static java.lang.foreign.ValueLayout.JAVA_SHORT;
|
||||
import static java.lang.foreign.ValueLayout.*;
|
||||
import static org.testng.Assert.*;
|
||||
|
||||
public class TestByteBuffer {
|
||||
@ -102,12 +96,12 @@ public class TestByteBuffer {
|
||||
}
|
||||
}
|
||||
|
||||
static final ValueLayout.OfChar BB_CHAR = JAVA_CHAR.withOrder(ByteOrder.BIG_ENDIAN).withBitAlignment(8);
|
||||
static final ValueLayout.OfShort BB_SHORT = JAVA_SHORT.withOrder(ByteOrder.BIG_ENDIAN).withBitAlignment(8);
|
||||
static final ValueLayout.OfInt BB_INT = JAVA_INT.withOrder(ByteOrder.BIG_ENDIAN).withBitAlignment(8);
|
||||
static final ValueLayout.OfLong BB_LONG = JAVA_LONG.withOrder(ByteOrder.BIG_ENDIAN).withBitAlignment(8);
|
||||
static final ValueLayout.OfFloat BB_FLOAT = JAVA_FLOAT.withOrder(ByteOrder.BIG_ENDIAN).withBitAlignment(8);
|
||||
static final ValueLayout.OfDouble BB_DOUBLE = JAVA_DOUBLE.withOrder(ByteOrder.BIG_ENDIAN).withBitAlignment(8);
|
||||
static final ValueLayout.OfChar BB_CHAR = JAVA_CHAR_UNALIGNED.withOrder(ByteOrder.BIG_ENDIAN);
|
||||
static final ValueLayout.OfShort BB_SHORT = JAVA_SHORT_UNALIGNED.withOrder(ByteOrder.BIG_ENDIAN);
|
||||
static final ValueLayout.OfInt BB_INT = JAVA_INT_UNALIGNED.withOrder(ByteOrder.BIG_ENDIAN);
|
||||
static final ValueLayout.OfLong BB_LONG = JAVA_LONG_UNALIGNED.withOrder(ByteOrder.BIG_ENDIAN);
|
||||
static final ValueLayout.OfFloat BB_FLOAT = JAVA_FLOAT_UNALIGNED.withOrder(ByteOrder.BIG_ENDIAN);
|
||||
static final ValueLayout.OfDouble BB_DOUBLE = JAVA_DOUBLE_UNALIGNED.withOrder(ByteOrder.BIG_ENDIAN);
|
||||
|
||||
static SequenceLayout tuples = MemoryLayout.sequenceLayout(500,
|
||||
MemoryLayout.structLayout(
|
||||
@ -385,7 +379,7 @@ public class TestByteBuffer {
|
||||
}
|
||||
|
||||
static void checkByteArrayAlignment(MemoryLayout layout) {
|
||||
if (layout.bitSize() > 32
|
||||
if (layout.byteSize() > 4
|
||||
&& System.getProperty("sun.arch.data.model").equals("32")) {
|
||||
throw new SkipException("avoid unaligned access on 32-bit system");
|
||||
}
|
||||
|
@ -125,7 +125,7 @@ public class TestFunctionDescriptor extends NativeTestHelper {
|
||||
C_INT,
|
||||
MemoryLayout.structLayout(C_INT, C_INT),
|
||||
MemoryLayout.sequenceLayout(3, C_INT),
|
||||
MemoryLayout.paddingLayout(32));
|
||||
MemoryLayout.paddingLayout(4));
|
||||
fd.toMethodType(); // should throw
|
||||
}
|
||||
|
||||
@ -143,27 +143,27 @@ public class TestFunctionDescriptor extends NativeTestHelper {
|
||||
|
||||
@Test(expectedExceptions = IllegalArgumentException.class)
|
||||
public void testBadPaddingInVoidFunction() {
|
||||
FunctionDescriptor.ofVoid(MemoryLayout.paddingLayout(8));
|
||||
FunctionDescriptor.ofVoid(MemoryLayout.paddingLayout(1));
|
||||
}
|
||||
|
||||
@Test(expectedExceptions = IllegalArgumentException.class)
|
||||
public void testBadPaddingInNonVoidFunction() {
|
||||
FunctionDescriptor.of(MemoryLayout.paddingLayout(8));
|
||||
FunctionDescriptor.of(MemoryLayout.paddingLayout(1));
|
||||
}
|
||||
|
||||
@Test(expectedExceptions = IllegalArgumentException.class)
|
||||
public void testBadPaddingInAppendArgLayouts() {
|
||||
FunctionDescriptor.ofVoid().appendArgumentLayouts(MemoryLayout.paddingLayout(8));
|
||||
FunctionDescriptor.ofVoid().appendArgumentLayouts(MemoryLayout.paddingLayout(1));
|
||||
}
|
||||
|
||||
@Test(expectedExceptions = IllegalArgumentException.class)
|
||||
public void testBadPaddingInInsertArgLayouts() {
|
||||
FunctionDescriptor.ofVoid().insertArgumentLayouts(0, MemoryLayout.paddingLayout(8));
|
||||
FunctionDescriptor.ofVoid().insertArgumentLayouts(0, MemoryLayout.paddingLayout(1));
|
||||
}
|
||||
|
||||
@Test(expectedExceptions = IllegalArgumentException.class)
|
||||
public void testBadPaddingInChangeRetLayout() {
|
||||
FunctionDescriptor.ofVoid().changeReturnLayout(MemoryLayout.paddingLayout(8));
|
||||
FunctionDescriptor.ofVoid().changeReturnLayout(MemoryLayout.paddingLayout(1));
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -85,14 +85,6 @@ public class TestHeapAlignment {
|
||||
}
|
||||
}
|
||||
|
||||
static final ValueLayout.OfChar JAVA_CHAR_ALIGNED = ValueLayout.JAVA_CHAR.withBitAlignment(16);
|
||||
static final ValueLayout.OfShort JAVA_SHORT_ALIGNED = ValueLayout.JAVA_SHORT.withBitAlignment(16);
|
||||
static final ValueLayout.OfInt JAVA_INT_ALIGNED = ValueLayout.JAVA_INT.withBitAlignment(32);
|
||||
static final ValueLayout.OfFloat JAVA_FLOAT_ALIGNED = ValueLayout.JAVA_FLOAT.withBitAlignment(32);
|
||||
static final ValueLayout.OfLong JAVA_LONG_ALIGNED = ValueLayout.JAVA_LONG.withBitAlignment(64);
|
||||
static final ValueLayout.OfDouble JAVA_DOUBLE_ALIGNED = ValueLayout.JAVA_DOUBLE.withBitAlignment(64);
|
||||
static final AddressLayout ADDRESS_ALIGNED = ValueLayout.ADDRESS.withBitAlignment(ValueLayout.ADDRESS.bitSize());
|
||||
|
||||
enum SegmentAndAlignment {
|
||||
HEAP_BYTE(MemorySegment.ofArray(new byte[8]), 1),
|
||||
HEAP_SHORT(MemorySegment.ofArray(new short[4]), 2),
|
||||
@ -118,13 +110,13 @@ public class TestHeapAlignment {
|
||||
for (SegmentAndAlignment testCase : SegmentAndAlignment.values()) {
|
||||
layouts.add(new Object[] { testCase.segment, testCase.align, (byte) 42, new byte[]{42}, ValueLayout.JAVA_BYTE, (Function<byte[], MemorySegment>)MemorySegment::ofArray });
|
||||
layouts.add(new Object[] { testCase.segment, testCase.align, true, null, ValueLayout.JAVA_BOOLEAN, null });
|
||||
layouts.add(new Object[] { testCase.segment, testCase.align, (char) 42, new char[]{42}, JAVA_CHAR_ALIGNED, (Function<char[], MemorySegment>)MemorySegment::ofArray });
|
||||
layouts.add(new Object[] { testCase.segment, testCase.align, (short) 42, new short[]{42}, JAVA_SHORT_ALIGNED, (Function<short[], MemorySegment>)MemorySegment::ofArray });
|
||||
layouts.add(new Object[] { testCase.segment, testCase.align, 42, new int[]{42}, JAVA_INT_ALIGNED, (Function<int[], MemorySegment>)MemorySegment::ofArray });
|
||||
layouts.add(new Object[] { testCase.segment, testCase.align, 42f, new float[]{42}, JAVA_FLOAT_ALIGNED, (Function<float[], MemorySegment>)MemorySegment::ofArray });
|
||||
layouts.add(new Object[] { testCase.segment, testCase.align, 42L, new long[]{42}, JAVA_LONG_ALIGNED, (Function<long[], MemorySegment>)MemorySegment::ofArray });
|
||||
layouts.add(new Object[] { testCase.segment, testCase.align, 42d, new double[]{42}, JAVA_DOUBLE_ALIGNED, (Function<double[], MemorySegment>)MemorySegment::ofArray });
|
||||
layouts.add(new Object[] { testCase.segment, testCase.align, MemorySegment.ofAddress(42), null, ADDRESS_ALIGNED, null });
|
||||
layouts.add(new Object[] { testCase.segment, testCase.align, (char) 42, new char[]{42}, ValueLayout.JAVA_CHAR, (Function<char[], MemorySegment>)MemorySegment::ofArray });
|
||||
layouts.add(new Object[] { testCase.segment, testCase.align, (short) 42, new short[]{42}, ValueLayout.JAVA_SHORT, (Function<short[], MemorySegment>)MemorySegment::ofArray });
|
||||
layouts.add(new Object[] { testCase.segment, testCase.align, 42, new int[]{42}, ValueLayout.JAVA_INT, (Function<int[], MemorySegment>)MemorySegment::ofArray });
|
||||
layouts.add(new Object[] { testCase.segment, testCase.align, 42f, new float[]{42}, ValueLayout.JAVA_FLOAT, (Function<float[], MemorySegment>)MemorySegment::ofArray });
|
||||
layouts.add(new Object[] { testCase.segment, testCase.align, 42L, new long[]{42}, ValueLayout.JAVA_LONG, (Function<long[], MemorySegment>)MemorySegment::ofArray });
|
||||
layouts.add(new Object[] { testCase.segment, testCase.align, 42d, new double[]{42}, ValueLayout.JAVA_DOUBLE, (Function<double[], MemorySegment>)MemorySegment::ofArray });
|
||||
layouts.add(new Object[] { testCase.segment, testCase.align, MemorySegment.ofAddress(42), null, ValueLayout.ADDRESS, null });
|
||||
}
|
||||
return layouts.toArray(new Object[0][]);
|
||||
}
|
||||
|
@ -111,52 +111,52 @@ public class TestIllegalLink extends NativeTestHelper {
|
||||
List<Object[]> cases = new ArrayList<>(Arrays.asList(new Object[][]{
|
||||
{
|
||||
FunctionDescriptor.of(MemoryLayout.sequenceLayout(2, C_INT)),
|
||||
"Unsupported layout: [2:i32]"
|
||||
"Unsupported layout: [2:i4]"
|
||||
},
|
||||
{
|
||||
FunctionDescriptor.ofVoid(MemoryLayout.sequenceLayout(2, C_INT)),
|
||||
"Unsupported layout: [2:i32]"
|
||||
"Unsupported layout: [2:i4]"
|
||||
},
|
||||
{
|
||||
FunctionDescriptor.ofVoid(C_INT.withBitAlignment(16)),
|
||||
"Layout bit alignment must be natural alignment"
|
||||
FunctionDescriptor.ofVoid(C_INT.withByteAlignment(2)),
|
||||
"Layout alignment must be natural alignment"
|
||||
},
|
||||
{
|
||||
FunctionDescriptor.ofVoid(C_POINTER.withBitAlignment(16)),
|
||||
"Layout bit alignment must be natural alignment"
|
||||
FunctionDescriptor.ofVoid(C_POINTER.withByteAlignment(2)),
|
||||
"Layout alignment must be natural alignment"
|
||||
},
|
||||
{
|
||||
FunctionDescriptor.ofVoid(ValueLayout.JAVA_CHAR.withBitAlignment(32)),
|
||||
"Layout bit alignment must be natural alignment"
|
||||
FunctionDescriptor.ofVoid(ValueLayout.JAVA_CHAR.withByteAlignment(4)),
|
||||
"Layout alignment must be natural alignment"
|
||||
},
|
||||
{
|
||||
FunctionDescriptor.ofVoid(MemoryLayout.structLayout(
|
||||
C_CHAR.withName("x").withBitAlignment(8),
|
||||
C_SHORT.withName("y").withBitAlignment(8),
|
||||
C_INT.withName("z").withBitAlignment(8)
|
||||
).withBitAlignment(8)),
|
||||
"Layout bit alignment must be natural alignment"
|
||||
C_CHAR.withName("x").withByteAlignment(1),
|
||||
C_SHORT.withName("y").withByteAlignment(1),
|
||||
C_INT.withName("z").withByteAlignment(1)
|
||||
).withByteAlignment(1)),
|
||||
"Layout alignment must be natural alignment"
|
||||
},
|
||||
{
|
||||
FunctionDescriptor.ofVoid(MemoryLayout.structLayout(
|
||||
MemoryLayout.structLayout(
|
||||
C_CHAR.withName("x").withBitAlignment(8),
|
||||
C_SHORT.withName("y").withBitAlignment(8),
|
||||
C_INT.withName("z").withBitAlignment(8)
|
||||
C_CHAR.withName("x").withByteAlignment(1),
|
||||
C_SHORT.withName("y").withByteAlignment(1),
|
||||
C_INT.withName("z").withByteAlignment(1)
|
||||
))),
|
||||
"Layout bit alignment must be natural alignment"
|
||||
"Layout alignment must be natural alignment"
|
||||
},
|
||||
{
|
||||
FunctionDescriptor.ofVoid(MemoryLayout.structLayout(
|
||||
MemoryLayout.sequenceLayout(
|
||||
C_INT.withBitAlignment(8)
|
||||
C_INT.withByteAlignment(1)
|
||||
))),
|
||||
"Layout bit alignment must be natural alignment"
|
||||
"Layout alignment must be natural alignment"
|
||||
},
|
||||
{
|
||||
FunctionDescriptor.ofVoid(MemoryLayout.structLayout(
|
||||
ValueLayout.JAVA_INT,
|
||||
MemoryLayout.paddingLayout(32), // no excess padding
|
||||
MemoryLayout.paddingLayout(4), // no excess padding
|
||||
ValueLayout.JAVA_INT)),
|
||||
"unexpected offset"
|
||||
},
|
||||
@ -181,7 +181,7 @@ public class TestIllegalLink extends NativeTestHelper {
|
||||
{
|
||||
FunctionDescriptor.ofVoid(MemoryLayout.structLayout(
|
||||
ValueLayout.JAVA_INT,
|
||||
MemoryLayout.paddingLayout(32))), // too much trailing padding
|
||||
MemoryLayout.paddingLayout(4))), // too much trailing padding
|
||||
"has unexpected size"
|
||||
},
|
||||
}));
|
||||
|
@ -46,48 +46,24 @@ import static org.testng.Assert.*;
|
||||
|
||||
public class TestLayoutPaths {
|
||||
|
||||
@Test(expectedExceptions = IllegalArgumentException.class)
|
||||
public void testBadBitSelectFromSeq() {
|
||||
SequenceLayout seq = MemoryLayout.sequenceLayout(5, JAVA_INT);
|
||||
seq.bitOffset(groupElement("foo"));
|
||||
}
|
||||
|
||||
@Test(expectedExceptions = IllegalArgumentException.class)
|
||||
public void testBadByteSelectFromSeq() {
|
||||
SequenceLayout seq = MemoryLayout.sequenceLayout(5, JAVA_INT);
|
||||
seq.byteOffset(groupElement("foo"));
|
||||
}
|
||||
|
||||
@Test(expectedExceptions = IllegalArgumentException.class)
|
||||
public void testBadBitSelectFromStruct() {
|
||||
GroupLayout g = MemoryLayout.structLayout(JAVA_INT);
|
||||
g.bitOffset(sequenceElement());
|
||||
}
|
||||
|
||||
@Test(expectedExceptions = IllegalArgumentException.class)
|
||||
public void testBadByteSelectFromStruct() {
|
||||
GroupLayout g = MemoryLayout.structLayout(JAVA_INT);
|
||||
g.byteOffset(sequenceElement());
|
||||
}
|
||||
|
||||
@Test(expectedExceptions = IllegalArgumentException.class)
|
||||
public void testBadBitSelectFromValue() {
|
||||
SequenceLayout seq = MemoryLayout.sequenceLayout(5, JAVA_INT);
|
||||
seq.bitOffset(sequenceElement(), sequenceElement());
|
||||
}
|
||||
|
||||
@Test(expectedExceptions = IllegalArgumentException.class)
|
||||
public void testBadByteSelectFromValue() {
|
||||
SequenceLayout seq = MemoryLayout.sequenceLayout(5, JAVA_INT);
|
||||
seq.byteOffset(sequenceElement(), sequenceElement());
|
||||
}
|
||||
|
||||
@Test(expectedExceptions = IllegalArgumentException.class)
|
||||
public void testUnknownBitStructField() {
|
||||
GroupLayout g = MemoryLayout.structLayout(JAVA_INT);
|
||||
g.bitOffset(groupElement("foo"));
|
||||
}
|
||||
|
||||
@Test(expectedExceptions = IllegalArgumentException.class)
|
||||
public void testUnknownByteStructField() {
|
||||
GroupLayout g = MemoryLayout.structLayout(JAVA_INT);
|
||||
@ -106,12 +82,6 @@ public class TestLayoutPaths {
|
||||
g.byteOffset(groupElement(-1));
|
||||
}
|
||||
|
||||
@Test(expectedExceptions = IllegalArgumentException.class)
|
||||
public void testBitOutOfBoundsSeqIndex() {
|
||||
SequenceLayout seq = MemoryLayout.sequenceLayout(5, JAVA_INT);
|
||||
seq.bitOffset(sequenceElement(6));
|
||||
}
|
||||
|
||||
@Test(expectedExceptions = IllegalArgumentException.class)
|
||||
public void testByteOutOfBoundsSeqIndex() {
|
||||
SequenceLayout seq = MemoryLayout.sequenceLayout(5, JAVA_INT);
|
||||
@ -123,12 +93,6 @@ public class TestLayoutPaths {
|
||||
sequenceElement(-2);
|
||||
}
|
||||
|
||||
@Test(expectedExceptions = IllegalArgumentException.class)
|
||||
public void testBitNegativeSeqIndex() {
|
||||
SequenceLayout seq = MemoryLayout.sequenceLayout(5, JAVA_INT);
|
||||
seq.bitOffset(sequenceElement(-2));
|
||||
}
|
||||
|
||||
@Test(expectedExceptions = IllegalArgumentException.class)
|
||||
public void testByteNegativeSeqIndex() {
|
||||
SequenceLayout seq = MemoryLayout.sequenceLayout(5, JAVA_INT);
|
||||
@ -138,7 +102,7 @@ public class TestLayoutPaths {
|
||||
@Test(expectedExceptions = IllegalArgumentException.class)
|
||||
public void testOutOfBoundsSeqRange() {
|
||||
SequenceLayout seq = MemoryLayout.sequenceLayout(5, JAVA_INT);
|
||||
seq.bitOffset(sequenceElement(6, 2));
|
||||
seq.byteOffset(sequenceElement(6, 2));
|
||||
}
|
||||
|
||||
@Test(expectedExceptions = IllegalArgumentException.class)
|
||||
@ -146,12 +110,6 @@ public class TestLayoutPaths {
|
||||
sequenceElement(-2, 2);
|
||||
}
|
||||
|
||||
@Test(expectedExceptions = IllegalArgumentException.class)
|
||||
public void testBitNegativeSeqRange() {
|
||||
SequenceLayout seq = MemoryLayout.sequenceLayout(5, JAVA_INT);
|
||||
seq.bitOffset(sequenceElement(-2, 2));
|
||||
}
|
||||
|
||||
@Test(expectedExceptions = IllegalArgumentException.class)
|
||||
public void testByteNegativeSeqRange() {
|
||||
SequenceLayout seq = MemoryLayout.sequenceLayout(5, JAVA_INT);
|
||||
@ -164,12 +122,6 @@ public class TestLayoutPaths {
|
||||
seq.varHandle(sequenceElement());
|
||||
}
|
||||
|
||||
@Test(expectedExceptions = IllegalArgumentException.class)
|
||||
public void testBitOffsetHandleBadRange() {
|
||||
SequenceLayout seq = MemoryLayout.sequenceLayout(5, MemoryLayout.structLayout(JAVA_INT));
|
||||
seq.bitOffsetHandle(sequenceElement(0, 1)); // ranges not accepted
|
||||
}
|
||||
|
||||
@Test(expectedExceptions = IllegalArgumentException.class)
|
||||
public void testByteOffsetHandleBadRange() {
|
||||
SequenceLayout seq = MemoryLayout.sequenceLayout(5, MemoryLayout.structLayout(JAVA_INT));
|
||||
@ -181,12 +133,6 @@ public class TestLayoutPaths {
|
||||
SequenceLayout seq = MemoryLayout.sequenceLayout(10, JAVA_INT);
|
||||
// bad path elements
|
||||
for (PathElement e : List.of( sequenceElement(), sequenceElement(0, 2) )) {
|
||||
try {
|
||||
seq.bitOffset(e);
|
||||
fail();
|
||||
} catch (IllegalArgumentException ex) {
|
||||
assertTrue(true);
|
||||
}
|
||||
try {
|
||||
seq.byteOffset(e);
|
||||
fail();
|
||||
@ -211,12 +157,12 @@ public class TestLayoutPaths {
|
||||
|
||||
@Test(dataProvider = "groupSelectors")
|
||||
public void testStructPaths(IntFunction<PathElement> groupSelector) {
|
||||
long[] offsets = { 0, 8, 24, 56 };
|
||||
long[] offsets = { 0, 1, 3, 7 };
|
||||
GroupLayout g = MemoryLayout.structLayout(
|
||||
ValueLayout.JAVA_BYTE.withName("0"),
|
||||
ValueLayout.JAVA_CHAR.withBitAlignment(8).withName("1"),
|
||||
ValueLayout.JAVA_FLOAT.withBitAlignment(8).withName("2"),
|
||||
ValueLayout.JAVA_LONG.withBitAlignment(8).withName("3")
|
||||
ValueLayout.JAVA_CHAR_UNALIGNED.withName("1"),
|
||||
ValueLayout.JAVA_FLOAT_UNALIGNED.withName("2"),
|
||||
ValueLayout.JAVA_LONG_UNALIGNED.withName("3")
|
||||
);
|
||||
|
||||
// test select
|
||||
@ -229,10 +175,8 @@ public class TestLayoutPaths {
|
||||
// test offset
|
||||
|
||||
for (int i = 0 ; i < 4 ; i++) {
|
||||
long bitOffset = g.bitOffset(groupSelector.apply(i));
|
||||
assertEquals(offsets[i], bitOffset);
|
||||
long byteOffset = g.byteOffset(groupSelector.apply(i));
|
||||
assertEquals((offsets[i]) >>> 3, byteOffset);
|
||||
assertEquals(offsets[i], byteOffset);
|
||||
}
|
||||
}
|
||||
|
||||
@ -256,10 +200,8 @@ public class TestLayoutPaths {
|
||||
// test offset
|
||||
|
||||
for (int i = 0 ; i < 4 ; i++) {
|
||||
long bitOffset = g.bitOffset(groupSelector.apply(i));
|
||||
assertEquals(offsets[i], bitOffset);
|
||||
long byteOffset = g.byteOffset(groupSelector.apply(i));
|
||||
assertEquals((offsets[i]) >>> 3, byteOffset);
|
||||
assertEquals(offsets[i], byteOffset);
|
||||
}
|
||||
}
|
||||
|
||||
@ -273,7 +215,7 @@ public class TestLayoutPaths {
|
||||
|
||||
@Test
|
||||
public void testSequencePaths() {
|
||||
long[] offsets = { 0, 8, 16, 24 };
|
||||
long[] offsets = { 0, 1, 2, 3 };
|
||||
SequenceLayout g = MemoryLayout.sequenceLayout(4, ValueLayout.JAVA_BYTE);
|
||||
|
||||
// test select
|
||||
@ -284,26 +226,18 @@ public class TestLayoutPaths {
|
||||
// test offset
|
||||
|
||||
for (int i = 0 ; i < 4 ; i++) {
|
||||
long bitOffset = g.bitOffset(sequenceElement(i));
|
||||
assertEquals(offsets[i], bitOffset);
|
||||
long byteOffset = g.byteOffset(sequenceElement(i));
|
||||
assertEquals((offsets[i]) >>> 3, byteOffset);
|
||||
assertEquals(offsets[i], byteOffset);
|
||||
}
|
||||
}
|
||||
|
||||
@Test(dataProvider = "testLayouts")
|
||||
public void testOffsetHandle(MemoryLayout layout, PathElement[] pathElements, long[] indexes,
|
||||
long expectedBitOffset) throws Throwable {
|
||||
MethodHandle bitOffsetHandle = layout.bitOffsetHandle(pathElements);
|
||||
bitOffsetHandle = bitOffsetHandle.asSpreader(long[].class, indexes.length);
|
||||
long actualBitOffset = (long) bitOffsetHandle.invokeExact(indexes);
|
||||
assertEquals(actualBitOffset, expectedBitOffset);
|
||||
if (expectedBitOffset % 8 == 0) {
|
||||
MethodHandle byteOffsetHandle = layout.byteOffsetHandle(pathElements);
|
||||
byteOffsetHandle = byteOffsetHandle.asSpreader(long[].class, indexes.length);
|
||||
long actualByteOffset = (long) byteOffsetHandle.invokeExact(indexes);
|
||||
assertEquals(actualByteOffset, expectedBitOffset / 8);
|
||||
}
|
||||
long expectedByteOffset) throws Throwable {
|
||||
MethodHandle byteOffsetHandle = layout.byteOffsetHandle(pathElements);
|
||||
byteOffsetHandle = byteOffsetHandle.asSpreader(long[].class, indexes.length);
|
||||
long actualByteOffset = (long) byteOffsetHandle.invokeExact(indexes);
|
||||
assertEquals(actualByteOffset, expectedByteOffset);
|
||||
}
|
||||
|
||||
@DataProvider
|
||||
@ -314,25 +248,25 @@ public class TestLayoutPaths {
|
||||
MemoryLayout.sequenceLayout(10, JAVA_INT),
|
||||
new PathElement[] { sequenceElement() },
|
||||
new long[] { 4 },
|
||||
JAVA_INT.bitSize() * 4
|
||||
JAVA_INT.byteSize() * 4
|
||||
});
|
||||
testCases.add(new Object[] {
|
||||
MemoryLayout.sequenceLayout(10, MemoryLayout.structLayout(JAVA_INT, JAVA_INT.withName("y"))),
|
||||
new PathElement[] { sequenceElement(), groupElement("y") },
|
||||
new long[] { 4 },
|
||||
(JAVA_INT.bitSize() * 2) * 4 + JAVA_INT.bitSize()
|
||||
(JAVA_INT.byteSize() * 2) * 4 + JAVA_INT.byteSize()
|
||||
});
|
||||
testCases.add(new Object[] {
|
||||
MemoryLayout.sequenceLayout(10, MemoryLayout.structLayout(MemoryLayout.paddingLayout(32), JAVA_INT.withName("y"))),
|
||||
MemoryLayout.sequenceLayout(10, MemoryLayout.structLayout(MemoryLayout.paddingLayout(4), JAVA_INT.withName("y"))),
|
||||
new PathElement[] { sequenceElement(), groupElement("y") },
|
||||
new long[] { 4 },
|
||||
(JAVA_INT.bitSize() + 32) * 4 + 32
|
||||
(JAVA_INT.byteSize() + 4) * 4 + 4
|
||||
});
|
||||
testCases.add(new Object[] {
|
||||
MemoryLayout.sequenceLayout(10, JAVA_INT),
|
||||
new PathElement[] { sequenceElement() },
|
||||
new long[] { 4 },
|
||||
JAVA_INT.bitSize() * 4
|
||||
JAVA_INT.byteSize() * 4
|
||||
});
|
||||
testCases.add(new Object[] {
|
||||
MemoryLayout.structLayout(
|
||||
@ -340,7 +274,7 @@ public class TestLayoutPaths {
|
||||
),
|
||||
new PathElement[] { groupElement("data"), sequenceElement() },
|
||||
new long[] { 4 },
|
||||
JAVA_INT.bitSize() * 4
|
||||
JAVA_INT.byteSize() * 4
|
||||
});
|
||||
|
||||
MemoryLayout complexLayout = MemoryLayout.structLayout(
|
||||
@ -358,25 +292,25 @@ public class TestLayoutPaths {
|
||||
complexLayout,
|
||||
new PathElement[] { groupElement("data"), sequenceElement(), sequenceElement(), groupElement("x") },
|
||||
new long[] { 0, 1 },
|
||||
(JAVA_INT.bitSize() * 2)
|
||||
(JAVA_INT.byteSize() * 2)
|
||||
});
|
||||
testCases.add(new Object[] {
|
||||
complexLayout,
|
||||
new PathElement[] { groupElement("data"), sequenceElement(), sequenceElement(), groupElement("x") },
|
||||
new long[] { 1, 0 },
|
||||
(JAVA_INT.bitSize() * 2) * 10
|
||||
(JAVA_INT.byteSize() * 2) * 10
|
||||
});
|
||||
testCases.add(new Object[] {
|
||||
complexLayout,
|
||||
new PathElement[] { groupElement("data"), sequenceElement(), sequenceElement(), groupElement("y") },
|
||||
new long[] { 0, 1 },
|
||||
(JAVA_INT.bitSize() * 2) + JAVA_INT.bitSize()
|
||||
(JAVA_INT.byteSize() * 2) + JAVA_INT.byteSize()
|
||||
});
|
||||
testCases.add(new Object[] {
|
||||
complexLayout,
|
||||
new PathElement[] { groupElement("data"), sequenceElement(), sequenceElement(), groupElement("y") },
|
||||
new long[] { 1, 0 },
|
||||
(JAVA_INT.bitSize() * 2) * 10 + JAVA_INT.bitSize()
|
||||
(JAVA_INT.byteSize() * 2) * 10 + JAVA_INT.byteSize()
|
||||
});
|
||||
|
||||
return testCases.toArray(Object[][]::new);
|
||||
@ -384,10 +318,7 @@ public class TestLayoutPaths {
|
||||
|
||||
@Test(dataProvider = "testLayouts")
|
||||
public void testSliceHandle(MemoryLayout layout, PathElement[] pathElements, long[] indexes,
|
||||
long expectedBitOffset) throws Throwable {
|
||||
if (expectedBitOffset % 8 != 0)
|
||||
throw new SkipException("Offset not a multiple of 8");
|
||||
|
||||
long expectedByteOffset) throws Throwable {
|
||||
MemoryLayout selected = layout.select(pathElements);
|
||||
MethodHandle sliceHandle = layout.sliceHandle(pathElements);
|
||||
sliceHandle = sliceHandle.asSpreader(long[].class, indexes.length);
|
||||
@ -395,7 +326,7 @@ public class TestLayoutPaths {
|
||||
try (Arena arena = Arena.ofConfined()) {
|
||||
MemorySegment segment = arena.allocate(layout);
|
||||
MemorySegment slice = (MemorySegment) sliceHandle.invokeExact(segment, indexes);
|
||||
assertEquals(slice.address() - segment.address(), expectedBitOffset / 8);
|
||||
assertEquals(slice.address() - segment.address(), expectedByteOffset);
|
||||
assertEquals(slice.byteSize(), selected.byteSize());
|
||||
}
|
||||
}
|
||||
|
@ -45,14 +45,14 @@ public class TestLayouts {
|
||||
|
||||
@Test(dataProvider = "badAlignments", expectedExceptions = IllegalArgumentException.class)
|
||||
public void testBadLayoutAlignment(MemoryLayout layout, long alignment) {
|
||||
layout.withBitAlignment(alignment);
|
||||
layout.withByteAlignment(alignment);
|
||||
}
|
||||
|
||||
@Test(dataProvider = "basicLayoutsAndAddressAndGroups")
|
||||
public void testEqualities(MemoryLayout layout) {
|
||||
|
||||
// Use another Type
|
||||
MemoryLayout differentType = MemoryLayout.paddingLayout(8);
|
||||
MemoryLayout differentType = MemoryLayout.paddingLayout(1);
|
||||
assertFalse(layout.equals(differentType));
|
||||
|
||||
// Use another name
|
||||
@ -60,7 +60,7 @@ public class TestLayouts {
|
||||
assertFalse(layout.equals(differentName));
|
||||
|
||||
// Use another alignment
|
||||
MemoryLayout differentAlignment = layout.withBitAlignment(layout.bitAlignment() * 2);
|
||||
MemoryLayout differentAlignment = layout.withByteAlignment(layout.byteAlignment() * 2);
|
||||
assertFalse(layout.equals(differentAlignment));
|
||||
|
||||
// Swap endian
|
||||
@ -78,7 +78,7 @@ public class TestLayouts {
|
||||
|
||||
assertFalse(layout.equals(MemoryLayout.sequenceLayout(13, JAVA_LONG)));
|
||||
|
||||
MemoryLayout other = layout.withBitAlignment(128).withBitAlignment(layout.bitAlignment());
|
||||
MemoryLayout other = layout.withByteAlignment(16).withByteAlignment(layout.byteAlignment());
|
||||
assertTrue(layout.equals(other));
|
||||
|
||||
}
|
||||
@ -124,37 +124,37 @@ public class TestLayouts {
|
||||
|
||||
@Test(dataProvider = "basicLayoutsAndAddressAndGroups", expectedExceptions = IllegalArgumentException.class)
|
||||
public void testGroupIllegalAlignmentNotPowerOfTwo(MemoryLayout layout) {
|
||||
layout.withBitAlignment(3);
|
||||
layout.withByteAlignment(9);
|
||||
}
|
||||
|
||||
@Test(dataProvider = "basicLayoutsAndAddressAndGroups", expectedExceptions = IllegalArgumentException.class)
|
||||
public void testGroupIllegalAlignmentNotGreaterOrEqualTo8(MemoryLayout layout) {
|
||||
layout.withBitAlignment(4);
|
||||
public void testGroupIllegalAlignmentNotGreaterOrEqualTo1(MemoryLayout layout) {
|
||||
layout.withByteAlignment(0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEqualsPadding() {
|
||||
PaddingLayout paddingLayout = MemoryLayout.paddingLayout(16);
|
||||
PaddingLayout paddingLayout = MemoryLayout.paddingLayout(2);
|
||||
testEqualities(paddingLayout);
|
||||
PaddingLayout paddingLayout2 = MemoryLayout.paddingLayout(32);
|
||||
PaddingLayout paddingLayout2 = MemoryLayout.paddingLayout(4);
|
||||
assertNotEquals(paddingLayout, paddingLayout2);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEmptyGroup() {
|
||||
MemoryLayout struct = MemoryLayout.structLayout();
|
||||
assertEquals(struct.bitSize(), 0);
|
||||
assertEquals(struct.bitAlignment(), 8);
|
||||
assertEquals(struct.byteSize(), 0);
|
||||
assertEquals(struct.byteAlignment(), 1);
|
||||
|
||||
MemoryLayout union = MemoryLayout.unionLayout();
|
||||
assertEquals(union.bitSize(), 0);
|
||||
assertEquals(union.bitAlignment(), 8);
|
||||
assertEquals(union.byteSize(), 0);
|
||||
assertEquals(union.byteAlignment(), 1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStructSizeAndAlign() {
|
||||
MemoryLayout struct = MemoryLayout.structLayout(
|
||||
MemoryLayout.paddingLayout(8),
|
||||
MemoryLayout.paddingLayout(1),
|
||||
ValueLayout.JAVA_BYTE,
|
||||
ValueLayout.JAVA_CHAR,
|
||||
ValueLayout.JAVA_INT,
|
||||
@ -166,21 +166,21 @@ public class TestLayouts {
|
||||
|
||||
@Test(dataProvider="basicLayouts")
|
||||
public void testPaddingNoAlign(MemoryLayout layout) {
|
||||
assertEquals(MemoryLayout.paddingLayout(layout.bitSize()).bitAlignment(), 8);
|
||||
assertEquals(MemoryLayout.paddingLayout(layout.byteSize()).byteAlignment(), 1);
|
||||
}
|
||||
|
||||
@Test(dataProvider="basicLayouts")
|
||||
public void testStructPaddingAndAlign(MemoryLayout layout) {
|
||||
MemoryLayout struct = MemoryLayout.structLayout(
|
||||
layout, MemoryLayout.paddingLayout(128 - layout.bitSize()));
|
||||
assertEquals(struct.bitAlignment(), layout.bitAlignment());
|
||||
layout, MemoryLayout.paddingLayout(16 - layout.byteSize()));
|
||||
assertEquals(struct.byteAlignment(), layout.byteAlignment());
|
||||
}
|
||||
|
||||
@Test(dataProvider="basicLayouts")
|
||||
public void testUnionPaddingAndAlign(MemoryLayout layout) {
|
||||
MemoryLayout struct = MemoryLayout.unionLayout(
|
||||
layout, MemoryLayout.paddingLayout(128 - layout.bitSize()));
|
||||
assertEquals(struct.bitAlignment(), layout.bitAlignment());
|
||||
layout, MemoryLayout.paddingLayout(16 - layout.byteSize()));
|
||||
assertEquals(struct.byteAlignment(), layout.byteAlignment());
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -204,7 +204,7 @@ public class TestLayouts {
|
||||
@Test(dataProvider = "basicLayouts")
|
||||
public void testSequenceInferredCount(MemoryLayout layout) {
|
||||
assertEquals(MemoryLayout.sequenceLayout(layout),
|
||||
MemoryLayout.sequenceLayout(Long.MAX_VALUE / layout.bitSize(), layout));
|
||||
MemoryLayout.sequenceLayout(Long.MAX_VALUE / layout.byteSize(), layout));
|
||||
}
|
||||
|
||||
public void testSequenceNegativeElementCount() {
|
||||
@ -233,23 +233,23 @@ public class TestLayouts {
|
||||
|
||||
@Test
|
||||
public void testPadding() {
|
||||
var padding = MemoryLayout.paddingLayout(8);
|
||||
var padding = MemoryLayout.paddingLayout(1);
|
||||
assertEquals(padding.byteAlignment(), 1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPaddingInStruct() {
|
||||
var padding = MemoryLayout.paddingLayout(8);
|
||||
var padding = MemoryLayout.paddingLayout(1);
|
||||
var struct = MemoryLayout.structLayout(padding);
|
||||
assertEquals(struct.byteAlignment(), 1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPaddingIllegalBitSize() {
|
||||
for (long bitSize : List.of(-8L, -1L, 0L, 1L, 7L)) {
|
||||
public void testPaddingIllegalByteSize() {
|
||||
for (long byteSize : List.of(-1L, 0L)) {
|
||||
try {
|
||||
MemoryLayout.paddingLayout(bitSize);
|
||||
fail("bitSize cannot be " + bitSize);
|
||||
MemoryLayout.paddingLayout(byteSize);
|
||||
fail("byte size cannot be " + byteSize);
|
||||
} catch (IllegalArgumentException ignore) {
|
||||
// Happy path
|
||||
}
|
||||
@ -259,9 +259,9 @@ public class TestLayouts {
|
||||
@Test
|
||||
public void testStructToString() {
|
||||
StructLayout padding = MemoryLayout.structLayout(JAVA_INT).withName("struct");
|
||||
assertEquals(padding.toString(), "[i32](struct)");
|
||||
var toStringUnaligned = padding.withBitAlignment(64).toString();
|
||||
assertEquals(toStringUnaligned, "64%[i32](struct)");
|
||||
assertEquals(padding.toString(), "[i4](struct)");
|
||||
var toStringUnaligned = padding.withByteAlignment(8).toString();
|
||||
assertEquals(toStringUnaligned, "8%[i4](struct)");
|
||||
}
|
||||
|
||||
@Test(dataProvider = "layoutKinds")
|
||||
@ -270,36 +270,36 @@ public class TestLayouts {
|
||||
}
|
||||
|
||||
@Test(dataProvider="layoutsAndAlignments")
|
||||
public void testAlignmentString(MemoryLayout layout, long bitAlign) {
|
||||
long[] alignments = { 8, 16, 32, 64, 128 };
|
||||
public void testAlignmentString(MemoryLayout layout, long byteAlign) {
|
||||
long[] alignments = { 1, 2, 4, 8, 16 };
|
||||
for (long a : alignments) {
|
||||
if (layout.bitAlignment() == bitAlign) {
|
||||
if (layout.byteAlignment() == byteAlign) {
|
||||
assertFalse(layout.toString().contains("%"));
|
||||
if (a >= layout.bitAlignment()) {
|
||||
assertEquals(layout.withBitAlignment(a).toString().contains("%"), a != bitAlign);
|
||||
if (a >= layout.byteAlignment()) {
|
||||
assertEquals(layout.withByteAlignment(a).toString().contains("%"), a != byteAlign);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test(dataProvider="layoutsAndAlignments")
|
||||
public void testBadBitAlignment(MemoryLayout layout, long bitAlign) {
|
||||
long[] alignments = { 8, 16, 32, 64, 128 };
|
||||
public void testBadByteAlignment(MemoryLayout layout, long byteAlign) {
|
||||
long[] alignments = { 1, 2, 4, 8, 16 };
|
||||
for (long a : alignments) {
|
||||
if (a < bitAlign && !(layout instanceof ValueLayout)) {
|
||||
assertThrows(IllegalArgumentException.class, () -> layout.withBitAlignment(a));
|
||||
if (a < byteAlign && !(layout instanceof ValueLayout)) {
|
||||
assertThrows(IllegalArgumentException.class, () -> layout.withByteAlignment(a));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test(dataProvider="layoutsAndAlignments", expectedExceptions = IllegalArgumentException.class)
|
||||
public void testBadSequenceElementAlignmentTooBig(MemoryLayout layout, long bitAlign) {
|
||||
layout = layout.withBitAlignment(layout.bitSize() * 2); // hyper-align
|
||||
public void testBadSequenceElementAlignmentTooBig(MemoryLayout layout, long byteAlign) {
|
||||
layout = layout.withByteAlignment(layout.byteSize() * 2); // hyper-align
|
||||
MemoryLayout.sequenceLayout(layout);
|
||||
}
|
||||
|
||||
@Test(dataProvider="layoutsAndAlignments")
|
||||
public void testBadSequenceElementSizeNotMultipleOfAlignment(MemoryLayout layout, long bitAlign) {
|
||||
public void testBadSequenceElementSizeNotMultipleOfAlignment(MemoryLayout layout, long byteAlign) {
|
||||
boolean shouldFail = layout.byteSize() % layout.byteAlignment() != 0;
|
||||
try {
|
||||
MemoryLayout.sequenceLayout(layout);
|
||||
@ -310,7 +310,7 @@ public class TestLayouts {
|
||||
}
|
||||
|
||||
@Test(dataProvider="layoutsAndAlignments")
|
||||
public void testBadSpliteratorElementSizeNotMultipleOfAlignment(MemoryLayout layout, long bitAlign) {
|
||||
public void testBadSpliteratorElementSizeNotMultipleOfAlignment(MemoryLayout layout, long byteAlign) {
|
||||
boolean shouldFail = layout.byteSize() % layout.byteAlignment() != 0;
|
||||
try (Arena arena = Arena.ofConfined()) {
|
||||
MemorySegment segment = arena.allocate(layout);
|
||||
@ -322,7 +322,7 @@ public class TestLayouts {
|
||||
}
|
||||
|
||||
@Test(dataProvider="layoutsAndAlignments")
|
||||
public void testBadElementsElementSizeNotMultipleOfAlignment(MemoryLayout layout, long bitAlign) {
|
||||
public void testBadElementsElementSizeNotMultipleOfAlignment(MemoryLayout layout, long byteAlign) {
|
||||
boolean shouldFail = layout.byteSize() % layout.byteAlignment() != 0;
|
||||
try (Arena arena = Arena.ofConfined()) {
|
||||
MemorySegment segment = arena.allocate(layout);
|
||||
@ -334,8 +334,8 @@ public class TestLayouts {
|
||||
}
|
||||
|
||||
@Test(dataProvider="layoutsAndAlignments", expectedExceptions = IllegalArgumentException.class)
|
||||
public void testBadStruct(MemoryLayout layout, long bitAlign) {
|
||||
layout = layout.withBitAlignment(layout.bitSize() * 2); // hyper-align
|
||||
public void testBadStruct(MemoryLayout layout, long byteAlign) {
|
||||
layout = layout.withByteAlignment(layout.byteSize() * 2); // hyper-align
|
||||
MemoryLayout.structLayout(layout, layout);
|
||||
}
|
||||
|
||||
@ -351,8 +351,8 @@ public class TestLayouts {
|
||||
LayoutKind[] layoutKinds = LayoutKind.values();
|
||||
Object[][] values = new Object[layoutKinds.length * 2][2];
|
||||
for (int i = 0; i < layoutKinds.length ; i++) {
|
||||
values[i * 2] = new Object[] { layoutKinds[i].layout, 3 }; // smaller than 8
|
||||
values[(i * 2) + 1] = new Object[] { layoutKinds[i].layout, 18 }; // not a power of 2
|
||||
values[i * 2] = new Object[] { layoutKinds[i].layout, 0 }; // smaller than 1
|
||||
values[(i * 2) + 1] = new Object[] { layoutKinds[i].layout, 5 }; // not a power of 2
|
||||
}
|
||||
return values;
|
||||
}
|
||||
@ -368,7 +368,7 @@ public class TestLayouts {
|
||||
VALUE_LE(size -> valueLayoutForSize((int)size).withOrder(ByteOrder.LITTLE_ENDIAN)),
|
||||
VALUE_BE(size -> valueLayoutForSize((int)size).withOrder(ByteOrder.BIG_ENDIAN)),
|
||||
PADDING(MemoryLayout::paddingLayout),
|
||||
SEQUENCE(size -> MemoryLayout.sequenceLayout(size, MemoryLayout.paddingLayout(8)));
|
||||
SEQUENCE(size -> MemoryLayout.sequenceLayout(size, MemoryLayout.paddingLayout(1)));
|
||||
|
||||
private final LongFunction<MemoryLayout> factory;
|
||||
|
||||
@ -393,10 +393,10 @@ public class TestLayouts {
|
||||
|
||||
enum LayoutKind {
|
||||
VALUE(ValueLayout.JAVA_BYTE),
|
||||
PADDING(MemoryLayout.paddingLayout(8)),
|
||||
SEQUENCE(MemoryLayout.sequenceLayout(1, MemoryLayout.paddingLayout(8))),
|
||||
STRUCT(MemoryLayout.structLayout(MemoryLayout.paddingLayout(8), MemoryLayout.paddingLayout(8))),
|
||||
UNION(MemoryLayout.unionLayout(MemoryLayout.paddingLayout(8), MemoryLayout.paddingLayout(8)));
|
||||
PADDING(MemoryLayout.paddingLayout(1)),
|
||||
SEQUENCE(MemoryLayout.sequenceLayout(1, MemoryLayout.paddingLayout(1))),
|
||||
STRUCT(MemoryLayout.structLayout(MemoryLayout.paddingLayout(1), MemoryLayout.paddingLayout(1))),
|
||||
UNION(MemoryLayout.unionLayout(MemoryLayout.paddingLayout(1), MemoryLayout.paddingLayout(1)));
|
||||
|
||||
final MemoryLayout layout;
|
||||
|
||||
@ -432,24 +432,24 @@ public class TestLayouts {
|
||||
int i = 0;
|
||||
//add basic layouts
|
||||
for (MemoryLayout l : basicLayoutsNoLongDouble) {
|
||||
layoutsAndAlignments.add(new Object[] { l, l.bitAlignment() });
|
||||
layoutsAndAlignments.add(new Object[] { l, l.byteAlignment() });
|
||||
}
|
||||
//add basic layouts wrapped in a sequence with given size
|
||||
for (MemoryLayout l : basicLayoutsNoLongDouble) {
|
||||
layoutsAndAlignments.add(new Object[] { MemoryLayout.sequenceLayout(4, l), l.bitAlignment() });
|
||||
layoutsAndAlignments.add(new Object[] { MemoryLayout.sequenceLayout(4, l), l.byteAlignment() });
|
||||
}
|
||||
//add basic layouts wrapped in a struct
|
||||
for (MemoryLayout l1 : basicLayoutsNoLongDouble) {
|
||||
for (MemoryLayout l2 : basicLayoutsNoLongDouble) {
|
||||
if (l1.byteSize() % l2.byteAlignment() != 0) continue; // second element is not aligned, skip
|
||||
long align = Math.max(l1.bitAlignment(), l2.bitAlignment());
|
||||
long align = Math.max(l1.byteAlignment(), l2.byteAlignment());
|
||||
layoutsAndAlignments.add(new Object[]{MemoryLayout.structLayout(l1, l2), align});
|
||||
}
|
||||
}
|
||||
//add basic layouts wrapped in a union
|
||||
for (MemoryLayout l1 : basicLayoutsNoLongDouble) {
|
||||
for (MemoryLayout l2 : basicLayoutsNoLongDouble) {
|
||||
long align = Math.max(l1.bitAlignment(), l2.bitAlignment());
|
||||
long align = Math.max(l1.byteAlignment(), l2.byteAlignment());
|
||||
layoutsAndAlignments.add(new Object[]{MemoryLayout.unionLayout(l1, l2), align});
|
||||
}
|
||||
}
|
||||
@ -484,7 +484,7 @@ public class TestLayouts {
|
||||
return Stream.of(
|
||||
MemoryLayout.sequenceLayout(10, JAVA_INT),
|
||||
MemoryLayout.sequenceLayout(JAVA_INT),
|
||||
MemoryLayout.structLayout(JAVA_INT, MemoryLayout.paddingLayout(32), JAVA_LONG),
|
||||
MemoryLayout.structLayout(JAVA_INT, MemoryLayout.paddingLayout(4), JAVA_LONG),
|
||||
MemoryLayout.unionLayout(JAVA_LONG, JAVA_DOUBLE)
|
||||
);
|
||||
}
|
||||
|
@ -89,10 +89,10 @@ public class TestLinker extends NativeTestHelper {
|
||||
FunctionDescriptor.ofVoid(structLayout(C_INT).withName("x")) },
|
||||
{ FunctionDescriptor.ofVoid(structLayout(C_INT)),
|
||||
FunctionDescriptor.ofVoid(structLayout(C_INT.withName("x"))) },
|
||||
{ FunctionDescriptor.ofVoid(structLayout(C_INT, paddingLayout(32), C_LONG_LONG)),
|
||||
FunctionDescriptor.ofVoid(structLayout(C_INT, paddingLayout(32), C_LONG_LONG.withName("x"))) },
|
||||
{ FunctionDescriptor.ofVoid(structLayout(C_INT, paddingLayout(32), C_LONG_LONG)),
|
||||
FunctionDescriptor.ofVoid(structLayout(C_INT, paddingLayout(32).withName("x"), C_LONG_LONG)) },
|
||||
{ FunctionDescriptor.ofVoid(structLayout(C_INT, paddingLayout(4), C_LONG_LONG)),
|
||||
FunctionDescriptor.ofVoid(structLayout(C_INT, paddingLayout(4), C_LONG_LONG.withName("x"))) },
|
||||
{ FunctionDescriptor.ofVoid(structLayout(C_INT, paddingLayout(4), C_LONG_LONG)),
|
||||
FunctionDescriptor.ofVoid(structLayout(C_INT, paddingLayout(4).withName("x"), C_LONG_LONG)) },
|
||||
{ FunctionDescriptor.ofVoid(structLayout(sequenceLayout(1, C_INT))),
|
||||
FunctionDescriptor.ofVoid(structLayout(sequenceLayout(1, C_INT).withName("x"))) },
|
||||
{ FunctionDescriptor.ofVoid(structLayout(sequenceLayout(1, C_INT))),
|
||||
|
@ -50,7 +50,7 @@ public class TestMemoryAccess {
|
||||
|
||||
@Test(dataProvider = "elements")
|
||||
public void testPaddedAccessByName(Function<MemorySegment, MemorySegment> viewFactory, MemoryLayout elemLayout, Checker checker) {
|
||||
GroupLayout layout = MemoryLayout.structLayout(MemoryLayout.paddingLayout(elemLayout.bitSize()), elemLayout.withName("elem"));
|
||||
GroupLayout layout = MemoryLayout.structLayout(MemoryLayout.paddingLayout(elemLayout.byteSize()), elemLayout.withName("elem"));
|
||||
testAccessInternal(viewFactory, layout, layout.varHandle(PathElement.groupElement("elem")), checker);
|
||||
}
|
||||
|
||||
@ -74,7 +74,7 @@ public class TestMemoryAccess {
|
||||
|
||||
@Test(dataProvider = "arrayElements")
|
||||
public void testPaddedArrayAccessByName(Function<MemorySegment, MemorySegment> viewFactory, MemoryLayout elemLayout, ArrayChecker checker) {
|
||||
SequenceLayout seq = MemoryLayout.sequenceLayout(10, MemoryLayout.structLayout(MemoryLayout.paddingLayout(elemLayout.bitSize()), elemLayout.withName("elem")));
|
||||
SequenceLayout seq = MemoryLayout.sequenceLayout(10, MemoryLayout.structLayout(MemoryLayout.paddingLayout(elemLayout.byteSize()), elemLayout.withName("elem")));
|
||||
testArrayAccessInternal(viewFactory, seq, seq.varHandle(MemoryLayout.PathElement.sequenceElement(), MemoryLayout.PathElement.groupElement("elem")), checker);
|
||||
}
|
||||
|
||||
@ -168,7 +168,7 @@ public class TestMemoryAccess {
|
||||
@Test(dataProvider = "matrixElements")
|
||||
public void testPaddedMatrixAccessByName(Function<MemorySegment, MemorySegment> viewFactory, MemoryLayout elemLayout, MatrixChecker checker) {
|
||||
SequenceLayout seq = MemoryLayout.sequenceLayout(20,
|
||||
MemoryLayout.sequenceLayout(10, MemoryLayout.structLayout(MemoryLayout.paddingLayout(elemLayout.bitSize()), elemLayout.withName("elem"))));
|
||||
MemoryLayout.sequenceLayout(10, MemoryLayout.structLayout(MemoryLayout.paddingLayout(elemLayout.byteSize()), elemLayout.withName("elem"))));
|
||||
testMatrixAccessInternal(viewFactory, seq,
|
||||
seq.varHandle(
|
||||
PathElement.sequenceElement(), PathElement.sequenceElement(), PathElement.groupElement("elem")),
|
||||
|
@ -95,7 +95,7 @@ public class TestMemoryAccessInstance {
|
||||
try (Arena arena = Arena.ofConfined()) {
|
||||
MemorySegment segment = arena.allocate(64, 1);
|
||||
T t = transform.apply(segment);
|
||||
L alignedLayout = (L)layout.withBitAlignment(layout.byteSize() * 8 * 2);
|
||||
L alignedLayout = (L)layout.withByteAlignment(layout.byteSize() * 2);
|
||||
try {
|
||||
segmentSetter.set(t, alignedLayout, 0, value);
|
||||
fail();
|
||||
|
@ -41,11 +41,10 @@ public class TestMemoryAlignment {
|
||||
@Test(dataProvider = "alignments")
|
||||
public void testAlignedAccess(long align) {
|
||||
ValueLayout layout = ValueLayout.JAVA_INT
|
||||
.withBitAlignment(32)
|
||||
.withOrder(ByteOrder.BIG_ENDIAN);
|
||||
assertEquals(layout.bitAlignment(), 32);
|
||||
ValueLayout aligned = layout.withBitAlignment(align);
|
||||
assertEquals(aligned.bitAlignment(), align); //unreasonable alignment here, to make sure access throws
|
||||
assertEquals(layout.byteAlignment(), 4);
|
||||
ValueLayout aligned = layout.withByteAlignment(align);
|
||||
assertEquals(aligned.byteAlignment(), align); //unreasonable alignment here, to make sure access throws
|
||||
VarHandle vh = aligned.varHandle();
|
||||
try (Arena arena = Arena.ofConfined()) {
|
||||
MemorySegment segment = arena.allocate(aligned);;
|
||||
@ -58,13 +57,12 @@ public class TestMemoryAlignment {
|
||||
@Test(dataProvider = "alignments")
|
||||
public void testUnalignedAccess(long align) {
|
||||
ValueLayout layout = ValueLayout.JAVA_INT
|
||||
.withBitAlignment(32)
|
||||
.withOrder(ByteOrder.BIG_ENDIAN);
|
||||
assertEquals(layout.bitAlignment(), 32);
|
||||
ValueLayout aligned = layout.withBitAlignment(align);
|
||||
assertEquals(layout.byteAlignment(), 4);
|
||||
ValueLayout aligned = layout.withByteAlignment(align);
|
||||
try (Arena arena = Arena.ofConfined()) {
|
||||
MemoryLayout alignedGroup = MemoryLayout.structLayout(MemoryLayout.paddingLayout(8), aligned);
|
||||
assertEquals(alignedGroup.bitAlignment(), align);
|
||||
MemoryLayout alignedGroup = MemoryLayout.structLayout(MemoryLayout.paddingLayout(1), aligned);
|
||||
assertEquals(alignedGroup.byteAlignment(), align);
|
||||
VarHandle vh = aligned.varHandle();
|
||||
MemorySegment segment = arena.allocate(alignedGroup);;
|
||||
vh.set(segment.asSlice(1L), -42);
|
||||
@ -77,20 +75,20 @@ public class TestMemoryAlignment {
|
||||
@Test(dataProvider = "alignments")
|
||||
public void testUnalignedPath(long align) {
|
||||
MemoryLayout layout = ValueLayout.JAVA_INT.withOrder(ByteOrder.BIG_ENDIAN);
|
||||
MemoryLayout aligned = layout.withBitAlignment(align).withName("value");
|
||||
MemoryLayout aligned = layout.withByteAlignment(align).withName("value");
|
||||
try {
|
||||
GroupLayout alignedGroup = MemoryLayout.structLayout(MemoryLayout.paddingLayout(8), aligned);
|
||||
GroupLayout alignedGroup = MemoryLayout.structLayout(MemoryLayout.paddingLayout(1), aligned);
|
||||
alignedGroup.varHandle(PathElement.groupElement("value"));
|
||||
assertEquals(align, 8); //this is the only case where path is aligned
|
||||
assertEquals(align, 1); //this is the only case where path is aligned
|
||||
} catch (IllegalArgumentException ex) {
|
||||
assertNotEquals(align, 8); //if align != 8, path is always unaligned
|
||||
assertNotEquals(align, 1); //if align != 8, path is always unaligned
|
||||
}
|
||||
}
|
||||
|
||||
@Test(dataProvider = "alignments")
|
||||
public void testUnalignedSequence(long align) {
|
||||
try {
|
||||
SequenceLayout layout = MemoryLayout.sequenceLayout(5, ValueLayout.JAVA_INT.withOrder(ByteOrder.BIG_ENDIAN).withBitAlignment(align));
|
||||
SequenceLayout layout = MemoryLayout.sequenceLayout(5, ValueLayout.JAVA_INT.withOrder(ByteOrder.BIG_ENDIAN).withByteAlignment(align));
|
||||
VarHandle vh = layout.varHandle(PathElement.sequenceElement());
|
||||
try (Arena arena = Arena.ofConfined()) {
|
||||
MemorySegment segment = arena.allocate(layout);;
|
||||
@ -99,7 +97,7 @@ public class TestMemoryAlignment {
|
||||
}
|
||||
}
|
||||
} catch (IllegalArgumentException ex) {
|
||||
assertTrue(align > 32); //if align > 32, access is always unaligned (for some elements)
|
||||
assertTrue(align > 4); //if align > 4, access is always unaligned (for some elements)
|
||||
}
|
||||
}
|
||||
|
||||
@ -109,10 +107,10 @@ public class TestMemoryAlignment {
|
||||
ValueLayout vShort = ValueLayout.JAVA_SHORT.withOrder(ByteOrder.BIG_ENDIAN);
|
||||
ValueLayout vInt = ValueLayout.JAVA_INT.withOrder(ByteOrder.BIG_ENDIAN);
|
||||
//mimic pragma pack(1)
|
||||
GroupLayout g = MemoryLayout.structLayout(vChar.withBitAlignment(8).withName("a"),
|
||||
vShort.withBitAlignment(8).withName("b"),
|
||||
vInt.withBitAlignment(8).withName("c"));
|
||||
assertEquals(g.bitAlignment(), 8);
|
||||
GroupLayout g = MemoryLayout.structLayout(vChar.withByteAlignment(1).withName("a"),
|
||||
vShort.withByteAlignment(1).withName("b"),
|
||||
vInt.withByteAlignment(1).withName("c"));
|
||||
assertEquals(g.byteAlignment(), 1);
|
||||
VarHandle vh_c = g.varHandle(PathElement.groupElement("a"));
|
||||
VarHandle vh_s = g.varHandle(PathElement.groupElement("b"));
|
||||
VarHandle vh_i = g.varHandle(PathElement.groupElement("c"));
|
||||
@ -129,7 +127,7 @@ public class TestMemoryAlignment {
|
||||
|
||||
@DataProvider(name = "alignments")
|
||||
public Object[][] createAlignments() {
|
||||
return LongStream.range(3, 32)
|
||||
return LongStream.range(1, 20)
|
||||
.mapToObj(v -> new Object[] { 1L << v })
|
||||
.toArray(Object[][]::new);
|
||||
}
|
||||
|
@ -161,7 +161,7 @@ public class TestNulls {
|
||||
addDefaultMapping(ValueLayout.OfFloat.class, ValueLayout.JAVA_FLOAT);
|
||||
addDefaultMapping(ValueLayout.OfLong.class, JAVA_LONG);
|
||||
addDefaultMapping(ValueLayout.OfDouble.class, ValueLayout.JAVA_DOUBLE);
|
||||
addDefaultMapping(PaddingLayout.class, MemoryLayout.paddingLayout(32));
|
||||
addDefaultMapping(PaddingLayout.class, MemoryLayout.paddingLayout(4));
|
||||
addDefaultMapping(GroupLayout.class, MemoryLayout.structLayout(ValueLayout.JAVA_INT));
|
||||
addDefaultMapping(StructLayout.class, MemoryLayout.structLayout(ValueLayout.JAVA_INT));
|
||||
addDefaultMapping(UnionLayout.class, MemoryLayout.unionLayout(ValueLayout.JAVA_INT));
|
||||
|
@ -56,17 +56,16 @@ import static org.testng.Assert.*;
|
||||
public class TestSegmentAllocators {
|
||||
|
||||
final static int ELEMS = 128;
|
||||
final static Class<?> ADDRESS_CARRIER = ValueLayout.ADDRESS.bitSize() == 64 ? long.class : int.class;
|
||||
|
||||
@Test(dataProvider = "scalarAllocations")
|
||||
@SuppressWarnings("unchecked")
|
||||
public <Z, L extends ValueLayout> void testAllocation(Z value, AllocationFactory allocationFactory, L layout, AllocationFunction<Z, L> allocationFunction, Function<MemoryLayout, VarHandle> handleFactory) {
|
||||
layout = (L)layout.withBitAlignment(layout.bitSize());
|
||||
layout = (L)layout.withByteAlignment(layout.byteSize());
|
||||
L[] layouts = (L[])new ValueLayout[] {
|
||||
layout,
|
||||
layout.withBitAlignment(layout.bitAlignment() * 2),
|
||||
layout.withBitAlignment(layout.bitAlignment() * 4),
|
||||
layout.withBitAlignment(layout.bitAlignment() * 8)
|
||||
layout.withByteAlignment(layout.byteAlignment() * 2),
|
||||
layout.withByteAlignment(layout.byteAlignment() * 4),
|
||||
layout.withByteAlignment(layout.byteAlignment() * 8)
|
||||
};
|
||||
for (L alignedLayout : layouts) {
|
||||
List<MemorySegment> addressList = new ArrayList<>();
|
||||
|
@ -108,13 +108,13 @@ public class TestSegmentCopy {
|
||||
@Test(expectedExceptions = IllegalArgumentException.class)
|
||||
public void testHyperAlignedSrc() {
|
||||
MemorySegment segment = MemorySegment.ofArray(new byte[] {1, 2, 3, 4});
|
||||
MemorySegment.copy(segment, 0, segment, JAVA_BYTE.withBitAlignment(16), 0, 4);
|
||||
MemorySegment.copy(segment, 0, segment, JAVA_BYTE.withByteAlignment(2), 0, 4);
|
||||
}
|
||||
|
||||
@Test(expectedExceptions = IllegalArgumentException.class)
|
||||
public void testHyperAlignedDst() {
|
||||
MemorySegment segment = MemorySegment.ofArray(new byte[] {1, 2, 3, 4});
|
||||
MemorySegment.copy(segment, JAVA_BYTE.withBitAlignment(16), 0, segment, 0, 4);
|
||||
MemorySegment.copy(segment, JAVA_BYTE.withByteAlignment(2), 0, segment, 0, 4);
|
||||
}
|
||||
|
||||
enum Type {
|
||||
|
@ -156,7 +156,7 @@ public class TestSpliterator {
|
||||
MemorySegment segment = scope.allocate(8, 1);
|
||||
// compute an alignment constraint (in bytes) which exceed that of the native segment
|
||||
long bigByteAlign = Long.lowestOneBit(segment.address()) << 1;
|
||||
segment.elements(MemoryLayout.sequenceLayout(2, ValueLayout.JAVA_INT.withBitAlignment(bigByteAlign * 8)));
|
||||
segment.elements(MemoryLayout.sequenceLayout(2, ValueLayout.JAVA_INT.withByteAlignment(bigByteAlign)));
|
||||
}
|
||||
|
||||
static long sumSingle(long acc, MemorySegment segment) {
|
||||
|
@ -55,7 +55,7 @@ public class TestUpcallHighArity extends CallGeneratorHelper {
|
||||
C_POINTER.withName("p0"),
|
||||
C_DOUBLE.withName("p1"),
|
||||
C_INT.withName("p2"),
|
||||
MemoryLayout.paddingLayout(32)
|
||||
MemoryLayout.paddingLayout(4)
|
||||
);
|
||||
|
||||
static {
|
||||
|
@ -59,7 +59,7 @@ public class TestUpcallStructScope extends NativeTestHelper {
|
||||
C_POINTER.withName("p0"),
|
||||
C_DOUBLE.withName("p1"),
|
||||
C_INT.withName("p2"),
|
||||
MemoryLayout.paddingLayout(32)
|
||||
MemoryLayout.paddingLayout(4)
|
||||
);
|
||||
|
||||
static {
|
||||
|
@ -41,114 +41,112 @@ public class TestValueLayouts {
|
||||
|
||||
@Test
|
||||
public void testByte() {
|
||||
testAligned(JAVA_BYTE, byte.class, Byte.SIZE);
|
||||
testAligned(JAVA_BYTE, byte.class, Byte.BYTES);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBoolean() {
|
||||
testAligned(JAVA_BOOLEAN, boolean.class, Byte.SIZE);
|
||||
testAligned(JAVA_BOOLEAN, boolean.class, Byte.BYTES);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testShort() {
|
||||
testAligned(JAVA_SHORT, short.class, Short.SIZE);
|
||||
testAligned(JAVA_SHORT, short.class, Short.BYTES);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testShortUnaligned() {
|
||||
testUnaligned(JAVA_SHORT_UNALIGNED, short.class, Short.SIZE);
|
||||
testUnaligned(JAVA_SHORT_UNALIGNED, short.class, Short.BYTES);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInt() {
|
||||
testAligned(JAVA_INT, int.class, Integer.SIZE);
|
||||
testAligned(JAVA_INT, int.class, Integer.BYTES);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIntUnaligned() {
|
||||
testUnaligned(JAVA_INT_UNALIGNED, int.class, Integer.SIZE);
|
||||
testUnaligned(JAVA_INT_UNALIGNED, int.class, Integer.BYTES);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLong() {
|
||||
testAligned(JAVA_LONG, long.class, Long.SIZE, ADDRESS.bitSize());
|
||||
testAligned(JAVA_LONG, long.class, Long.BYTES, ADDRESS.byteSize());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLongUnaligned() {
|
||||
testUnaligned(JAVA_LONG_UNALIGNED, long.class, Long.SIZE);
|
||||
testUnaligned(JAVA_LONG_UNALIGNED, long.class, Long.BYTES);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFloat() {
|
||||
testAligned(JAVA_FLOAT, float.class, Float.SIZE);
|
||||
testAligned(JAVA_FLOAT, float.class, Float.BYTES);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFloatUnaligned() {
|
||||
testUnaligned(JAVA_FLOAT_UNALIGNED, float.class, Float.SIZE);
|
||||
testUnaligned(JAVA_FLOAT_UNALIGNED, float.class, Float.BYTES);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDouble() {
|
||||
testAligned(JAVA_DOUBLE, double.class, Double.SIZE, ADDRESS.bitSize());
|
||||
testAligned(JAVA_DOUBLE, double.class, Double.BYTES, ADDRESS.byteSize());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDoubleUnaligned() {
|
||||
testUnaligned(JAVA_DOUBLE_UNALIGNED, double.class, Double.SIZE);
|
||||
testUnaligned(JAVA_DOUBLE_UNALIGNED, double.class, Double.BYTES);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testChar() {
|
||||
testAligned(JAVA_CHAR, char.class, Character.SIZE);
|
||||
testAligned(JAVA_CHAR, char.class, Character.BYTES);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCharUnaligned() {
|
||||
testUnaligned(JAVA_CHAR_UNALIGNED, char.class, Character.SIZE);
|
||||
testUnaligned(JAVA_CHAR_UNALIGNED, char.class, Character.BYTES);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAddress() {
|
||||
testAligned(ADDRESS, MemorySegment.class, Unsafe.ADDRESS_SIZE * 8L);
|
||||
testAligned(ADDRESS, MemorySegment.class, Unsafe.ADDRESS_SIZE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAddressUnaligned() {
|
||||
testUnaligned(ADDRESS_UNALIGNED, MemorySegment.class, Unsafe.ADDRESS_SIZE * 8L);
|
||||
testUnaligned(ADDRESS_UNALIGNED, MemorySegment.class, Unsafe.ADDRESS_SIZE);
|
||||
}
|
||||
|
||||
void testAligned(ValueLayout layout,
|
||||
Class<?> carrier,
|
||||
long bitSize) {
|
||||
test(layout, carrier, bitSize, bitSize);
|
||||
long byteSize) {
|
||||
test(layout, carrier, byteSize, byteSize);
|
||||
}
|
||||
|
||||
void testAligned(ValueLayout layout,
|
||||
Class<?> carrier,
|
||||
long bitSize,
|
||||
long bitAlignment) {
|
||||
test(layout, carrier, bitSize, bitAlignment);
|
||||
long byteSize,
|
||||
long byteAlignment) {
|
||||
test(layout, carrier, byteSize, byteAlignment);
|
||||
}
|
||||
|
||||
void testUnaligned(ValueLayout layout,
|
||||
Class<?> carrier,
|
||||
long bitSize) {
|
||||
test(layout, carrier, bitSize, Byte.SIZE);
|
||||
long byteSize) {
|
||||
test(layout, carrier, byteSize, Byte.BYTES);
|
||||
}
|
||||
|
||||
void test(ValueLayout layout,
|
||||
Class<?> carrier,
|
||||
long bitSize,
|
||||
long bitAlignment) {
|
||||
long byteSize,
|
||||
long byteAlignment) {
|
||||
assertEquals(layout.carrier(), carrier);
|
||||
assertEquals(layout.bitSize(), bitSize);
|
||||
assertEquals(layout.byteSize(), byteSize);
|
||||
assertEquals(layout.order(), ByteOrder.nativeOrder());
|
||||
assertEquals(layout.bitAlignment(), bitAlignment);
|
||||
assertEquals(layout.byteAlignment(), byteAlignment);
|
||||
assertTrue(layout.name().isEmpty());
|
||||
assertEquals(layout.byteSize(), layout.bitSize() / 8);
|
||||
assertEquals(layout.byteAlignment(), layout.bitAlignment() / 8);
|
||||
|
||||
}
|
||||
|
||||
|
@ -53,7 +53,7 @@ public class TestVarHandleCombinators {
|
||||
|
||||
@Test(expectedExceptions = IllegalArgumentException.class)
|
||||
public void testUnalignedElement() {
|
||||
VarHandle vh = MethodHandles.memorySegmentViewVarHandle(ValueLayout.JAVA_BYTE.withBitAlignment(32));
|
||||
VarHandle vh = MethodHandles.memorySegmentViewVarHandle(ValueLayout.JAVA_BYTE.withByteAlignment(4));
|
||||
MemorySegment segment = MemorySegment.ofArray(new byte[4]);
|
||||
vh.get(segment, 2L); //should throw
|
||||
//FIXME: the VH only checks the alignment of the segment, which is fine if the VH is derived from layouts,
|
||||
@ -63,7 +63,7 @@ public class TestVarHandleCombinators {
|
||||
|
||||
@Test
|
||||
public void testAlign() {
|
||||
VarHandle vh = MethodHandles.memorySegmentViewVarHandle(ValueLayout.JAVA_BYTE.withBitAlignment(16));
|
||||
VarHandle vh = MethodHandles.memorySegmentViewVarHandle(ValueLayout.JAVA_BYTE.withByteAlignment(2));
|
||||
|
||||
Arena scope = Arena.ofAuto();
|
||||
MemorySegment segment = scope.allocate(1L, 2);
|
||||
@ -73,8 +73,8 @@ public class TestVarHandleCombinators {
|
||||
|
||||
@Test
|
||||
public void testByteOrderLE() {
|
||||
VarHandle vh = MethodHandles.memorySegmentViewVarHandle(ValueLayout.JAVA_SHORT
|
||||
.withOrder(ByteOrder.LITTLE_ENDIAN).withBitAlignment(8));
|
||||
VarHandle vh = MethodHandles.memorySegmentViewVarHandle(ValueLayout.JAVA_SHORT_UNALIGNED
|
||||
.withOrder(ByteOrder.LITTLE_ENDIAN));
|
||||
byte[] arr = new byte[2];
|
||||
MemorySegment segment = MemorySegment.ofArray(arr);
|
||||
vh.set(segment, 0L, (short) 0xFF);
|
||||
@ -84,8 +84,8 @@ public class TestVarHandleCombinators {
|
||||
|
||||
@Test
|
||||
public void testByteOrderBE() {
|
||||
VarHandle vh = MethodHandles.memorySegmentViewVarHandle(ValueLayout.JAVA_SHORT
|
||||
.withOrder(ByteOrder.BIG_ENDIAN).withBitAlignment(8));
|
||||
VarHandle vh = MethodHandles.memorySegmentViewVarHandle(ValueLayout.JAVA_SHORT_UNALIGNED
|
||||
.withOrder(ByteOrder.BIG_ENDIAN));
|
||||
byte[] arr = new byte[2];
|
||||
MemorySegment segment = MemorySegment.ofArray(arr);
|
||||
vh.set(segment, 0L, (short) 0xFF);
|
||||
@ -100,7 +100,7 @@ public class TestVarHandleCombinators {
|
||||
|
||||
//[10 : [5 : [x32 i32]]]
|
||||
|
||||
VarHandle vh = MethodHandles.memorySegmentViewVarHandle(ValueLayout.JAVA_INT.withBitAlignment(32));
|
||||
VarHandle vh = MethodHandles.memorySegmentViewVarHandle(ValueLayout.JAVA_INT);
|
||||
int count = 0;
|
||||
try (Arena arena = Arena.ofConfined()) {
|
||||
MemorySegment segment = arena.allocate(inner_size * outer_size * 8, 4);
|
||||
|
@ -50,14 +50,14 @@ public class TestLayoutEquality {
|
||||
@Test(dataProvider = "layoutConstants")
|
||||
public void testReconstructedEquality(ValueLayout layout) {
|
||||
ValueLayout newLayout = ValueLayouts.valueLayout(layout.carrier(), layout.order());
|
||||
newLayout = newLayout.withBitAlignment(layout.bitAlignment());
|
||||
newLayout = newLayout.withByteAlignment(layout.byteAlignment());
|
||||
if (layout instanceof AddressLayout addressLayout && addressLayout.targetLayout().isPresent()) {
|
||||
newLayout = ((AddressLayout)newLayout).withTargetLayout(addressLayout.targetLayout().get());
|
||||
}
|
||||
|
||||
// properties should be equal
|
||||
assertEquals(newLayout.bitSize(), layout.bitSize());
|
||||
assertEquals(newLayout.bitAlignment(), layout.bitAlignment());
|
||||
assertEquals(newLayout.byteSize(), layout.byteSize());
|
||||
assertEquals(newLayout.byteAlignment(), layout.byteAlignment());
|
||||
assertEquals(newLayout.name(), layout.name());
|
||||
|
||||
// layouts should be equals
|
||||
|
@ -187,7 +187,7 @@ public class TestLinuxAArch64CallArranger extends CallArrangerTestBase {
|
||||
bufferLoad(8, long.class), vmStore(r1, long.class),
|
||||
}},
|
||||
// struct s { float a; /* padding */ double b };
|
||||
{ MemoryLayout.structLayout(C_FLOAT, MemoryLayout.paddingLayout(32), C_DOUBLE),
|
||||
{ MemoryLayout.structLayout(C_FLOAT, MemoryLayout.paddingLayout(4), C_DOUBLE),
|
||||
new Binding[] {
|
||||
dup(),
|
||||
// s.a
|
||||
|
@ -205,7 +205,7 @@ public class TestRISCV64CallArranger extends CallArrangerTestBase {
|
||||
}
|
||||
},
|
||||
// struct s { float a; /* padding */ double b };
|
||||
{ MemoryLayout.structLayout(C_FLOAT, MemoryLayout.paddingLayout(32), C_DOUBLE),
|
||||
{ MemoryLayout.structLayout(C_FLOAT, MemoryLayout.paddingLayout(4), C_DOUBLE),
|
||||
new Binding[]{
|
||||
dup(),
|
||||
// s.a
|
||||
@ -257,7 +257,7 @@ public class TestRISCV64CallArranger extends CallArrangerTestBase {
|
||||
|
||||
@Test
|
||||
public void testStructFA2() {
|
||||
MemoryLayout fa = MemoryLayout.structLayout(C_FLOAT, MemoryLayout.paddingLayout(32), C_DOUBLE);
|
||||
MemoryLayout fa = MemoryLayout.structLayout(C_FLOAT, MemoryLayout.paddingLayout(4), C_DOUBLE);
|
||||
|
||||
MethodType mt = MethodType.methodType(MemorySegment.class, float.class, int.class, MemorySegment.class);
|
||||
FunctionDescriptor fd = FunctionDescriptor.of(fa, C_FLOAT, C_INT, fa);
|
||||
|
@ -118,7 +118,7 @@ public class TestSysVCallArranger extends CallArrangerTestBase {
|
||||
public void testNestedUnion() {
|
||||
MemoryLayout POINT = MemoryLayout.structLayout(
|
||||
C_INT,
|
||||
MemoryLayout.paddingLayout(32),
|
||||
MemoryLayout.paddingLayout(4),
|
||||
MemoryLayout.unionLayout(
|
||||
MemoryLayout.structLayout(C_INT, C_INT),
|
||||
C_LONG
|
||||
|
@ -88,14 +88,14 @@ public class TestNested extends NativeTestHelper {
|
||||
C_LONG_LONG.withName("f1"),
|
||||
C_DOUBLE.withName("f2"),
|
||||
C_INT.withName("f3"),
|
||||
MemoryLayout.paddingLayout(32)
|
||||
MemoryLayout.paddingLayout(4)
|
||||
).withName("S1");
|
||||
static final UnionLayout U1 = MemoryLayout.unionLayout(
|
||||
C_SHORT.withName("f0"),
|
||||
C_LONG_LONG.withName("f1"),
|
||||
C_SHORT.withName("f2"),
|
||||
MemoryLayout.sequenceLayout(4, MemoryLayout.sequenceLayout(3, C_CHAR)).withName("f3"),
|
||||
MemoryLayout.paddingLayout(128)
|
||||
MemoryLayout.paddingLayout(16)
|
||||
).withName("U1");
|
||||
static final UnionLayout U17 = MemoryLayout.unionLayout(
|
||||
C_CHAR.withName("f0"),
|
||||
@ -107,7 +107,7 @@ public class TestNested extends NativeTestHelper {
|
||||
U17.withName("f0"),
|
||||
MemoryLayout.sequenceLayout(4, C_LONG_LONG).withName("f1"),
|
||||
C_SHORT.withName("f2"),
|
||||
MemoryLayout.paddingLayout(48)
|
||||
MemoryLayout.paddingLayout(6)
|
||||
).withName("S2");
|
||||
static final StructLayout S3 = MemoryLayout.structLayout(
|
||||
C_FLOAT.withName("f0"),
|
||||
@ -117,12 +117,12 @@ public class TestNested extends NativeTestHelper {
|
||||
).withName("S3");
|
||||
static final StructLayout S4 = MemoryLayout.structLayout(
|
||||
MemoryLayout.sequenceLayout(2, C_SHORT).withName("f0"),
|
||||
MemoryLayout.paddingLayout(32),
|
||||
MemoryLayout.paddingLayout(4),
|
||||
S1.withName("f1")
|
||||
).withName("S4");
|
||||
static final StructLayout S5 = MemoryLayout.structLayout(
|
||||
C_FLOAT.withName("f0"),
|
||||
MemoryLayout.paddingLayout(32),
|
||||
MemoryLayout.paddingLayout(4),
|
||||
C_POINTER.withName("f1"),
|
||||
S4.withName("f2")
|
||||
).withName("S5");
|
||||
@ -139,7 +139,7 @@ public class TestNested extends NativeTestHelper {
|
||||
C_DOUBLE.withName("f0"),
|
||||
C_SHORT.withName("f1"),
|
||||
C_SHORT.withName("f2"),
|
||||
MemoryLayout.paddingLayout(32),
|
||||
MemoryLayout.paddingLayout(4),
|
||||
C_LONG_LONG.withName("f3")
|
||||
).withName("S7");
|
||||
static final UnionLayout U3 = MemoryLayout.unionLayout(
|
||||
@ -169,16 +169,16 @@ public class TestNested extends NativeTestHelper {
|
||||
static final StructLayout S8 = MemoryLayout.structLayout(
|
||||
MemoryLayout.sequenceLayout(3, C_DOUBLE).withName("f0"),
|
||||
U7.withName("f1"),
|
||||
MemoryLayout.paddingLayout(48),
|
||||
MemoryLayout.paddingLayout(6),
|
||||
C_POINTER.withName("f2"),
|
||||
C_POINTER.withName("f3")
|
||||
).withName("S8");
|
||||
static final StructLayout S9 = MemoryLayout.structLayout(
|
||||
C_CHAR.withName("f0"),
|
||||
MemoryLayout.paddingLayout(56),
|
||||
MemoryLayout.paddingLayout(7),
|
||||
MemoryLayout.sequenceLayout(2, C_DOUBLE).withName("f1"),
|
||||
C_CHAR.withName("f2"),
|
||||
MemoryLayout.paddingLayout(56),
|
||||
MemoryLayout.paddingLayout(7),
|
||||
S8.withName("f3")
|
||||
).withName("S9");
|
||||
static final UnionLayout U8 = MemoryLayout.unionLayout(
|
||||
@ -207,7 +207,7 @@ public class TestNested extends NativeTestHelper {
|
||||
static final StructLayout S11 = MemoryLayout.structLayout(
|
||||
C_SHORT.withName("f0"),
|
||||
C_CHAR.withName("f1"),
|
||||
MemoryLayout.paddingLayout(8)
|
||||
MemoryLayout.paddingLayout(1)
|
||||
).withName("S11");
|
||||
static final UnionLayout U12 = MemoryLayout.unionLayout(
|
||||
C_FLOAT.withName("f0"),
|
||||
@ -237,10 +237,10 @@ public class TestNested extends NativeTestHelper {
|
||||
static final StructLayout S13 = MemoryLayout.structLayout(
|
||||
C_INT.withName("f0"),
|
||||
C_CHAR.withName("f1"),
|
||||
MemoryLayout.paddingLayout(24),
|
||||
MemoryLayout.paddingLayout(3),
|
||||
C_POINTER.withName("f2"),
|
||||
C_CHAR.withName("f3"),
|
||||
MemoryLayout.paddingLayout(56)
|
||||
MemoryLayout.paddingLayout(7)
|
||||
).withName("S13");
|
||||
static final StructLayout S14 = MemoryLayout.structLayout(
|
||||
C_LONG_LONG.withName("f0")
|
||||
|
@ -31,8 +31,8 @@ import java.util.concurrent.CountDownLatch;
|
||||
* Test native threads attaching implicitly to the VM by means of an upcall.
|
||||
*/
|
||||
public class ImplicitAttach {
|
||||
private static final ValueLayout.OfInt C_INT = ValueLayout.JAVA_INT.withBitAlignment(32);
|
||||
private static final AddressLayout C_POINTER = ValueLayout.ADDRESS.withBitAlignment(64);
|
||||
private static final ValueLayout.OfInt C_INT = ValueLayout.JAVA_INT;
|
||||
private static final AddressLayout C_POINTER = ValueLayout.ADDRESS;
|
||||
|
||||
private static volatile CountDownLatch latch;
|
||||
|
||||
|
@ -54,7 +54,7 @@ public class Byte128VectorLoadStoreTests extends AbstractVectorLoadStoreTest {
|
||||
|
||||
static final int INVOC_COUNT = Integer.getInteger("jdk.incubator.vector.test.loop-iterations", 100);
|
||||
|
||||
static final ValueLayout.OfByte ELEMENT_LAYOUT = ValueLayout.JAVA_BYTE.withBitAlignment(8);
|
||||
static final ValueLayout.OfByte ELEMENT_LAYOUT = ValueLayout.JAVA_BYTE.withByteAlignment(1);
|
||||
|
||||
|
||||
static final int BUFFER_REPS = Integer.getInteger("jdk.incubator.vector.test.buffer-vectors", 25000 / 128);
|
||||
|
@ -54,7 +54,7 @@ public class Byte256VectorLoadStoreTests extends AbstractVectorLoadStoreTest {
|
||||
|
||||
static final int INVOC_COUNT = Integer.getInteger("jdk.incubator.vector.test.loop-iterations", 100);
|
||||
|
||||
static final ValueLayout.OfByte ELEMENT_LAYOUT = ValueLayout.JAVA_BYTE.withBitAlignment(8);
|
||||
static final ValueLayout.OfByte ELEMENT_LAYOUT = ValueLayout.JAVA_BYTE.withByteAlignment(1);
|
||||
|
||||
|
||||
static final int BUFFER_REPS = Integer.getInteger("jdk.incubator.vector.test.buffer-vectors", 25000 / 256);
|
||||
|
@ -54,7 +54,7 @@ public class Byte512VectorLoadStoreTests extends AbstractVectorLoadStoreTest {
|
||||
|
||||
static final int INVOC_COUNT = Integer.getInteger("jdk.incubator.vector.test.loop-iterations", 100);
|
||||
|
||||
static final ValueLayout.OfByte ELEMENT_LAYOUT = ValueLayout.JAVA_BYTE.withBitAlignment(8);
|
||||
static final ValueLayout.OfByte ELEMENT_LAYOUT = ValueLayout.JAVA_BYTE.withByteAlignment(1);
|
||||
|
||||
|
||||
static final int BUFFER_REPS = Integer.getInteger("jdk.incubator.vector.test.buffer-vectors", 25000 / 512);
|
||||
|
@ -54,7 +54,7 @@ public class Byte64VectorLoadStoreTests extends AbstractVectorLoadStoreTest {
|
||||
|
||||
static final int INVOC_COUNT = Integer.getInteger("jdk.incubator.vector.test.loop-iterations", 100);
|
||||
|
||||
static final ValueLayout.OfByte ELEMENT_LAYOUT = ValueLayout.JAVA_BYTE.withBitAlignment(8);
|
||||
static final ValueLayout.OfByte ELEMENT_LAYOUT = ValueLayout.JAVA_BYTE.withByteAlignment(1);
|
||||
|
||||
|
||||
static final int BUFFER_REPS = Integer.getInteger("jdk.incubator.vector.test.buffer-vectors", 25000 / 64);
|
||||
|
@ -56,7 +56,7 @@ public class ByteMaxVectorLoadStoreTests extends AbstractVectorLoadStoreTest {
|
||||
|
||||
static final int INVOC_COUNT = Integer.getInteger("jdk.incubator.vector.test.loop-iterations", 100);
|
||||
|
||||
static final ValueLayout.OfByte ELEMENT_LAYOUT = ValueLayout.JAVA_BYTE.withBitAlignment(8);
|
||||
static final ValueLayout.OfByte ELEMENT_LAYOUT = ValueLayout.JAVA_BYTE.withByteAlignment(1);
|
||||
|
||||
static VectorShape getMaxBit() {
|
||||
return VectorShape.S_Max_BIT;
|
||||
|
@ -54,7 +54,7 @@ public class Double128VectorLoadStoreTests extends AbstractVectorLoadStoreTest {
|
||||
|
||||
static final int INVOC_COUNT = Integer.getInteger("jdk.incubator.vector.test.loop-iterations", 100);
|
||||
|
||||
static final ValueLayout.OfDouble ELEMENT_LAYOUT = ValueLayout.JAVA_DOUBLE.withBitAlignment(8);
|
||||
static final ValueLayout.OfDouble ELEMENT_LAYOUT = ValueLayout.JAVA_DOUBLE.withByteAlignment(1);
|
||||
|
||||
|
||||
static final int BUFFER_REPS = Integer.getInteger("jdk.incubator.vector.test.buffer-vectors", 25000 / 128);
|
||||
|
@ -54,7 +54,7 @@ public class Double256VectorLoadStoreTests extends AbstractVectorLoadStoreTest {
|
||||
|
||||
static final int INVOC_COUNT = Integer.getInteger("jdk.incubator.vector.test.loop-iterations", 100);
|
||||
|
||||
static final ValueLayout.OfDouble ELEMENT_LAYOUT = ValueLayout.JAVA_DOUBLE.withBitAlignment(8);
|
||||
static final ValueLayout.OfDouble ELEMENT_LAYOUT = ValueLayout.JAVA_DOUBLE.withByteAlignment(1);
|
||||
|
||||
|
||||
static final int BUFFER_REPS = Integer.getInteger("jdk.incubator.vector.test.buffer-vectors", 25000 / 256);
|
||||
|
@ -54,7 +54,7 @@ public class Double512VectorLoadStoreTests extends AbstractVectorLoadStoreTest {
|
||||
|
||||
static final int INVOC_COUNT = Integer.getInteger("jdk.incubator.vector.test.loop-iterations", 100);
|
||||
|
||||
static final ValueLayout.OfDouble ELEMENT_LAYOUT = ValueLayout.JAVA_DOUBLE.withBitAlignment(8);
|
||||
static final ValueLayout.OfDouble ELEMENT_LAYOUT = ValueLayout.JAVA_DOUBLE.withByteAlignment(1);
|
||||
|
||||
|
||||
static final int BUFFER_REPS = Integer.getInteger("jdk.incubator.vector.test.buffer-vectors", 25000 / 512);
|
||||
|
@ -54,7 +54,7 @@ public class Double64VectorLoadStoreTests extends AbstractVectorLoadStoreTest {
|
||||
|
||||
static final int INVOC_COUNT = Integer.getInteger("jdk.incubator.vector.test.loop-iterations", 100);
|
||||
|
||||
static final ValueLayout.OfDouble ELEMENT_LAYOUT = ValueLayout.JAVA_DOUBLE.withBitAlignment(8);
|
||||
static final ValueLayout.OfDouble ELEMENT_LAYOUT = ValueLayout.JAVA_DOUBLE.withByteAlignment(1);
|
||||
|
||||
|
||||
static final int BUFFER_REPS = Integer.getInteger("jdk.incubator.vector.test.buffer-vectors", 25000 / 64);
|
||||
|
@ -56,7 +56,7 @@ public class DoubleMaxVectorLoadStoreTests extends AbstractVectorLoadStoreTest {
|
||||
|
||||
static final int INVOC_COUNT = Integer.getInteger("jdk.incubator.vector.test.loop-iterations", 100);
|
||||
|
||||
static final ValueLayout.OfDouble ELEMENT_LAYOUT = ValueLayout.JAVA_DOUBLE.withBitAlignment(8);
|
||||
static final ValueLayout.OfDouble ELEMENT_LAYOUT = ValueLayout.JAVA_DOUBLE.withByteAlignment(1);
|
||||
|
||||
static VectorShape getMaxBit() {
|
||||
return VectorShape.S_Max_BIT;
|
||||
|
@ -54,7 +54,7 @@ public class Float128VectorLoadStoreTests extends AbstractVectorLoadStoreTest {
|
||||
|
||||
static final int INVOC_COUNT = Integer.getInteger("jdk.incubator.vector.test.loop-iterations", 100);
|
||||
|
||||
static final ValueLayout.OfFloat ELEMENT_LAYOUT = ValueLayout.JAVA_FLOAT.withBitAlignment(8);
|
||||
static final ValueLayout.OfFloat ELEMENT_LAYOUT = ValueLayout.JAVA_FLOAT.withByteAlignment(1);
|
||||
|
||||
|
||||
static final int BUFFER_REPS = Integer.getInteger("jdk.incubator.vector.test.buffer-vectors", 25000 / 128);
|
||||
|
@ -54,7 +54,7 @@ public class Float256VectorLoadStoreTests extends AbstractVectorLoadStoreTest {
|
||||
|
||||
static final int INVOC_COUNT = Integer.getInteger("jdk.incubator.vector.test.loop-iterations", 100);
|
||||
|
||||
static final ValueLayout.OfFloat ELEMENT_LAYOUT = ValueLayout.JAVA_FLOAT.withBitAlignment(8);
|
||||
static final ValueLayout.OfFloat ELEMENT_LAYOUT = ValueLayout.JAVA_FLOAT.withByteAlignment(1);
|
||||
|
||||
|
||||
static final int BUFFER_REPS = Integer.getInteger("jdk.incubator.vector.test.buffer-vectors", 25000 / 256);
|
||||
|
@ -54,7 +54,7 @@ public class Float512VectorLoadStoreTests extends AbstractVectorLoadStoreTest {
|
||||
|
||||
static final int INVOC_COUNT = Integer.getInteger("jdk.incubator.vector.test.loop-iterations", 100);
|
||||
|
||||
static final ValueLayout.OfFloat ELEMENT_LAYOUT = ValueLayout.JAVA_FLOAT.withBitAlignment(8);
|
||||
static final ValueLayout.OfFloat ELEMENT_LAYOUT = ValueLayout.JAVA_FLOAT.withByteAlignment(1);
|
||||
|
||||
|
||||
static final int BUFFER_REPS = Integer.getInteger("jdk.incubator.vector.test.buffer-vectors", 25000 / 512);
|
||||
|
@ -54,7 +54,7 @@ public class Float64VectorLoadStoreTests extends AbstractVectorLoadStoreTest {
|
||||
|
||||
static final int INVOC_COUNT = Integer.getInteger("jdk.incubator.vector.test.loop-iterations", 100);
|
||||
|
||||
static final ValueLayout.OfFloat ELEMENT_LAYOUT = ValueLayout.JAVA_FLOAT.withBitAlignment(8);
|
||||
static final ValueLayout.OfFloat ELEMENT_LAYOUT = ValueLayout.JAVA_FLOAT.withByteAlignment(1);
|
||||
|
||||
|
||||
static final int BUFFER_REPS = Integer.getInteger("jdk.incubator.vector.test.buffer-vectors", 25000 / 64);
|
||||
|
@ -56,7 +56,7 @@ public class FloatMaxVectorLoadStoreTests extends AbstractVectorLoadStoreTest {
|
||||
|
||||
static final int INVOC_COUNT = Integer.getInteger("jdk.incubator.vector.test.loop-iterations", 100);
|
||||
|
||||
static final ValueLayout.OfFloat ELEMENT_LAYOUT = ValueLayout.JAVA_FLOAT.withBitAlignment(8);
|
||||
static final ValueLayout.OfFloat ELEMENT_LAYOUT = ValueLayout.JAVA_FLOAT.withByteAlignment(1);
|
||||
|
||||
static VectorShape getMaxBit() {
|
||||
return VectorShape.S_Max_BIT;
|
||||
|
@ -54,7 +54,7 @@ public class Int128VectorLoadStoreTests extends AbstractVectorLoadStoreTest {
|
||||
|
||||
static final int INVOC_COUNT = Integer.getInteger("jdk.incubator.vector.test.loop-iterations", 100);
|
||||
|
||||
static final ValueLayout.OfInt ELEMENT_LAYOUT = ValueLayout.JAVA_INT.withBitAlignment(8);
|
||||
static final ValueLayout.OfInt ELEMENT_LAYOUT = ValueLayout.JAVA_INT.withByteAlignment(1);
|
||||
|
||||
|
||||
static final int BUFFER_REPS = Integer.getInteger("jdk.incubator.vector.test.buffer-vectors", 25000 / 128);
|
||||
|
@ -54,7 +54,7 @@ public class Int256VectorLoadStoreTests extends AbstractVectorLoadStoreTest {
|
||||
|
||||
static final int INVOC_COUNT = Integer.getInteger("jdk.incubator.vector.test.loop-iterations", 100);
|
||||
|
||||
static final ValueLayout.OfInt ELEMENT_LAYOUT = ValueLayout.JAVA_INT.withBitAlignment(8);
|
||||
static final ValueLayout.OfInt ELEMENT_LAYOUT = ValueLayout.JAVA_INT.withByteAlignment(1);
|
||||
|
||||
|
||||
static final int BUFFER_REPS = Integer.getInteger("jdk.incubator.vector.test.buffer-vectors", 25000 / 256);
|
||||
|
@ -54,7 +54,7 @@ public class Int512VectorLoadStoreTests extends AbstractVectorLoadStoreTest {
|
||||
|
||||
static final int INVOC_COUNT = Integer.getInteger("jdk.incubator.vector.test.loop-iterations", 100);
|
||||
|
||||
static final ValueLayout.OfInt ELEMENT_LAYOUT = ValueLayout.JAVA_INT.withBitAlignment(8);
|
||||
static final ValueLayout.OfInt ELEMENT_LAYOUT = ValueLayout.JAVA_INT.withByteAlignment(1);
|
||||
|
||||
|
||||
static final int BUFFER_REPS = Integer.getInteger("jdk.incubator.vector.test.buffer-vectors", 25000 / 512);
|
||||
|
@ -54,7 +54,7 @@ public class Int64VectorLoadStoreTests extends AbstractVectorLoadStoreTest {
|
||||
|
||||
static final int INVOC_COUNT = Integer.getInteger("jdk.incubator.vector.test.loop-iterations", 100);
|
||||
|
||||
static final ValueLayout.OfInt ELEMENT_LAYOUT = ValueLayout.JAVA_INT.withBitAlignment(8);
|
||||
static final ValueLayout.OfInt ELEMENT_LAYOUT = ValueLayout.JAVA_INT.withByteAlignment(1);
|
||||
|
||||
|
||||
static final int BUFFER_REPS = Integer.getInteger("jdk.incubator.vector.test.buffer-vectors", 25000 / 64);
|
||||
|
@ -56,7 +56,7 @@ public class IntMaxVectorLoadStoreTests extends AbstractVectorLoadStoreTest {
|
||||
|
||||
static final int INVOC_COUNT = Integer.getInteger("jdk.incubator.vector.test.loop-iterations", 100);
|
||||
|
||||
static final ValueLayout.OfInt ELEMENT_LAYOUT = ValueLayout.JAVA_INT.withBitAlignment(8);
|
||||
static final ValueLayout.OfInt ELEMENT_LAYOUT = ValueLayout.JAVA_INT.withByteAlignment(1);
|
||||
|
||||
static VectorShape getMaxBit() {
|
||||
return VectorShape.S_Max_BIT;
|
||||
|
@ -54,7 +54,7 @@ public class Long128VectorLoadStoreTests extends AbstractVectorLoadStoreTest {
|
||||
|
||||
static final int INVOC_COUNT = Integer.getInteger("jdk.incubator.vector.test.loop-iterations", 100);
|
||||
|
||||
static final ValueLayout.OfLong ELEMENT_LAYOUT = ValueLayout.JAVA_LONG.withBitAlignment(8);
|
||||
static final ValueLayout.OfLong ELEMENT_LAYOUT = ValueLayout.JAVA_LONG.withByteAlignment(1);
|
||||
|
||||
|
||||
static final int BUFFER_REPS = Integer.getInteger("jdk.incubator.vector.test.buffer-vectors", 25000 / 128);
|
||||
|
@ -54,7 +54,7 @@ public class Long256VectorLoadStoreTests extends AbstractVectorLoadStoreTest {
|
||||
|
||||
static final int INVOC_COUNT = Integer.getInteger("jdk.incubator.vector.test.loop-iterations", 100);
|
||||
|
||||
static final ValueLayout.OfLong ELEMENT_LAYOUT = ValueLayout.JAVA_LONG.withBitAlignment(8);
|
||||
static final ValueLayout.OfLong ELEMENT_LAYOUT = ValueLayout.JAVA_LONG.withByteAlignment(1);
|
||||
|
||||
|
||||
static final int BUFFER_REPS = Integer.getInteger("jdk.incubator.vector.test.buffer-vectors", 25000 / 256);
|
||||
|
@ -54,7 +54,7 @@ public class Long512VectorLoadStoreTests extends AbstractVectorLoadStoreTest {
|
||||
|
||||
static final int INVOC_COUNT = Integer.getInteger("jdk.incubator.vector.test.loop-iterations", 100);
|
||||
|
||||
static final ValueLayout.OfLong ELEMENT_LAYOUT = ValueLayout.JAVA_LONG.withBitAlignment(8);
|
||||
static final ValueLayout.OfLong ELEMENT_LAYOUT = ValueLayout.JAVA_LONG.withByteAlignment(1);
|
||||
|
||||
|
||||
static final int BUFFER_REPS = Integer.getInteger("jdk.incubator.vector.test.buffer-vectors", 25000 / 512);
|
||||
|
@ -54,7 +54,7 @@ public class Long64VectorLoadStoreTests extends AbstractVectorLoadStoreTest {
|
||||
|
||||
static final int INVOC_COUNT = Integer.getInteger("jdk.incubator.vector.test.loop-iterations", 100);
|
||||
|
||||
static final ValueLayout.OfLong ELEMENT_LAYOUT = ValueLayout.JAVA_LONG.withBitAlignment(8);
|
||||
static final ValueLayout.OfLong ELEMENT_LAYOUT = ValueLayout.JAVA_LONG.withByteAlignment(1);
|
||||
|
||||
|
||||
static final int BUFFER_REPS = Integer.getInteger("jdk.incubator.vector.test.buffer-vectors", 25000 / 64);
|
||||
|
@ -56,7 +56,7 @@ public class LongMaxVectorLoadStoreTests extends AbstractVectorLoadStoreTest {
|
||||
|
||||
static final int INVOC_COUNT = Integer.getInteger("jdk.incubator.vector.test.loop-iterations", 100);
|
||||
|
||||
static final ValueLayout.OfLong ELEMENT_LAYOUT = ValueLayout.JAVA_LONG.withBitAlignment(8);
|
||||
static final ValueLayout.OfLong ELEMENT_LAYOUT = ValueLayout.JAVA_LONG.withByteAlignment(1);
|
||||
|
||||
static VectorShape getMaxBit() {
|
||||
return VectorShape.S_Max_BIT;
|
||||
|
@ -54,7 +54,7 @@ public class Short128VectorLoadStoreTests extends AbstractVectorLoadStoreTest {
|
||||
|
||||
static final int INVOC_COUNT = Integer.getInteger("jdk.incubator.vector.test.loop-iterations", 100);
|
||||
|
||||
static final ValueLayout.OfShort ELEMENT_LAYOUT = ValueLayout.JAVA_SHORT.withBitAlignment(8);
|
||||
static final ValueLayout.OfShort ELEMENT_LAYOUT = ValueLayout.JAVA_SHORT.withByteAlignment(1);
|
||||
|
||||
|
||||
static final int BUFFER_REPS = Integer.getInteger("jdk.incubator.vector.test.buffer-vectors", 25000 / 128);
|
||||
|
@ -54,7 +54,7 @@ public class Short256VectorLoadStoreTests extends AbstractVectorLoadStoreTest {
|
||||
|
||||
static final int INVOC_COUNT = Integer.getInteger("jdk.incubator.vector.test.loop-iterations", 100);
|
||||
|
||||
static final ValueLayout.OfShort ELEMENT_LAYOUT = ValueLayout.JAVA_SHORT.withBitAlignment(8);
|
||||
static final ValueLayout.OfShort ELEMENT_LAYOUT = ValueLayout.JAVA_SHORT.withByteAlignment(1);
|
||||
|
||||
|
||||
static final int BUFFER_REPS = Integer.getInteger("jdk.incubator.vector.test.buffer-vectors", 25000 / 256);
|
||||
|
@ -54,7 +54,7 @@ public class Short512VectorLoadStoreTests extends AbstractVectorLoadStoreTest {
|
||||
|
||||
static final int INVOC_COUNT = Integer.getInteger("jdk.incubator.vector.test.loop-iterations", 100);
|
||||
|
||||
static final ValueLayout.OfShort ELEMENT_LAYOUT = ValueLayout.JAVA_SHORT.withBitAlignment(8);
|
||||
static final ValueLayout.OfShort ELEMENT_LAYOUT = ValueLayout.JAVA_SHORT.withByteAlignment(1);
|
||||
|
||||
|
||||
static final int BUFFER_REPS = Integer.getInteger("jdk.incubator.vector.test.buffer-vectors", 25000 / 512);
|
||||
|
@ -54,7 +54,7 @@ public class Short64VectorLoadStoreTests extends AbstractVectorLoadStoreTest {
|
||||
|
||||
static final int INVOC_COUNT = Integer.getInteger("jdk.incubator.vector.test.loop-iterations", 100);
|
||||
|
||||
static final ValueLayout.OfShort ELEMENT_LAYOUT = ValueLayout.JAVA_SHORT.withBitAlignment(8);
|
||||
static final ValueLayout.OfShort ELEMENT_LAYOUT = ValueLayout.JAVA_SHORT.withByteAlignment(1);
|
||||
|
||||
|
||||
static final int BUFFER_REPS = Integer.getInteger("jdk.incubator.vector.test.buffer-vectors", 25000 / 64);
|
||||
|
@ -56,7 +56,7 @@ public class ShortMaxVectorLoadStoreTests extends AbstractVectorLoadStoreTest {
|
||||
|
||||
static final int INVOC_COUNT = Integer.getInteger("jdk.incubator.vector.test.loop-iterations", 100);
|
||||
|
||||
static final ValueLayout.OfShort ELEMENT_LAYOUT = ValueLayout.JAVA_SHORT.withBitAlignment(8);
|
||||
static final ValueLayout.OfShort ELEMENT_LAYOUT = ValueLayout.JAVA_SHORT.withByteAlignment(1);
|
||||
|
||||
static VectorShape getMaxBit() {
|
||||
return VectorShape.S_Max_BIT;
|
||||
|
@ -67,7 +67,7 @@ public class $vectorteststype$ extends AbstractVectorLoadStoreTest {
|
||||
|
||||
static final int INVOC_COUNT = Integer.getInteger("jdk.incubator.vector.test.loop-iterations", 100);
|
||||
|
||||
static final ValueLayout.Of$Type$ ELEMENT_LAYOUT = ValueLayout.JAVA_$TYPE$.withBitAlignment(8);
|
||||
static final ValueLayout.Of$Type$ ELEMENT_LAYOUT = ValueLayout.JAVA_$TYPE$.withByteAlignment(1);
|
||||
|
||||
#if[MaxBit]
|
||||
static VectorShape getMaxBit() {
|
||||
|
Loading…
x
Reference in New Issue
Block a user