< prev index next >

src/jdk.incubator.foreign/share/classes/jdk/incubator/foreign/MemoryLayout.java

Print this page




 154 
 155     /**
 156      * Return the <em>name</em> (if any) associated with this layout.
 157      *
 158      * @return the layout <em>name</em> (if any).
 159      * @see MemoryLayout#withName(String)
 160      */
 161     Optional<String> name();
 162 
 163     /**
 164      * Attach a <em>name</em> to this layout.
 165      *
 166      * @param name the layout name.
 167      * @return a new layout which is the same as this layout, except for the <em>name</em> associated to it.
 168      * @see MemoryLayout#name()
 169      */
 170     MemoryLayout withName(String name);
 171 
 172     /**
 173      * Returns the alignment constraint associated with this layout, expressed in bits. Layout alignment defines a power
 174      * of two A which is the bitwise alignment of the layout. If A&gt;=8 then A/8 is the number of bytes that must be aligned
 175      * for any pointer that correctly points to this layout. Thus:
 176      *
 177      * <ul>
 178      * <li>A=8 means unaligned (in the usual sense), which is common in packets.</li>
 179      * <li>A=64 means word aligned (on LP64), A=32 int aligned, A=16 short aligned, etc.</li>
 180      * <li>A=512 is the most strict alignment required by the x86/SV ABI (for AVX-512 data).</li>
 181      * </ul>
 182      *
 183      * @return the layout alignment constraint, in bits.
 184      */
 185     long bitAlignment();
 186 
 187     /**
 188      * Returns the alignment constraint associated with this layout, expressed in bytes. Layout alignment defines a power
 189      * of two A which is the bytewise alignment of the layout, where A is the number of bytes that must be aligned
 190      * for any pointer that correctly points to this layout. Thus:
 191      *
 192      * <ul>
 193      * <li>A=1 means unaligned (in the usual sense), which is common in packets.</li>
 194      * <li>A=8 means word aligned (on LP64), A=4 int aligned, A=2 short aligned, etc.</li>
 195      * <li>A=64 is the most strict alignment required by the x86/SV ABI (for AVX-512 data).</li>
 196      * </ul>
 197      *
 198      * @return the layout alignment constraint, in bytes.
 199      * @throws UnsupportedOperationException if {@code bitAlignment()} is not a multiple of 8.
 200      */
 201     default long byteAlignment() {
 202         return Utils.bitsToBytesOrThrow(bitAlignment(),
 203                 () -> new UnsupportedOperationException("Cannot compute byte alignment; bit alignment is not a multiple of 8"));
 204     }
 205 
 206     /**
 207      * Creates a new layout which features the desired alignment constraint.
 208      *
 209      * @param bitAlignment the layout alignment constraint, expressed in bits.
 210      * @return a new layout which is the same as this layout, except for the alignment constraint associated to it.
 211      * @throws IllegalArgumentException if {@code bitAlignment} is not a power of two, or if it's less than than 8.
 212      */
 213     MemoryLayout withBitAlignment(long bitAlignment);
 214 
 215     /**




 154 
 155     /**
 156      * Return the <em>name</em> (if any) associated with this layout.
 157      *
 158      * @return the layout <em>name</em> (if any).
 159      * @see MemoryLayout#withName(String)
 160      */
 161     Optional<String> name();
 162 
 163     /**
 164      * Attach a <em>name</em> to this layout.
 165      *
 166      * @param name the layout name.
 167      * @return a new layout which is the same as this layout, except for the <em>name</em> associated to it.
 168      * @see MemoryLayout#name()
 169      */
 170     MemoryLayout withName(String name);
 171 
 172     /**
 173      * Returns the alignment constraint associated with this layout, expressed in bits. Layout alignment defines a power
 174      * 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
 175      * bytes that must be aligned for any pointer that correctly points to this layout. Thus:
 176      *
 177      * <ul>
 178      * <li>{@code A=8} means unaligned (in the usual sense), which is common in packets.</li>
 179      * <li>{@code A=64} means word aligned (on LP64), {@code A=32} int aligned, {@code A=16} short aligned, etc.</li>
 180      * <li>{@code A=512} is the most strict alignment required by the x86/SV ABI (for AVX-512 data).</li>
 181      * </ul>
 182      *
 183      * @return the layout alignment constraint, in bits.
 184      */
 185     long bitAlignment();
 186 
 187     /**
 188      * Returns the alignment constraint associated with this layout, expressed in bytes. Layout alignment defines a power
 189      * 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
 190      * for any pointer that correctly points to this layout. Thus:
 191      *
 192      * <ul>
 193      * <li>{@code A=1} means unaligned (in the usual sense), which is common in packets.</li>
 194      * <li>{@code A=8} means word aligned (on LP64), {@code A=4} int aligned, {@code A=2} short aligned, etc.</li>
 195      * <li>{@code A=64} is the most strict alignment required by the x86/SV ABI (for AVX-512 data).</li>
 196      * </ul>
 197      *
 198      * @return the layout alignment constraint, in bytes.
 199      * @throws UnsupportedOperationException if {@code bitAlignment()} is not a multiple of 8.
 200      */
 201     default long byteAlignment() {
 202         return Utils.bitsToBytesOrThrow(bitAlignment(),
 203                 () -> new UnsupportedOperationException("Cannot compute byte alignment; bit alignment is not a multiple of 8"));
 204     }
 205 
 206     /**
 207      * Creates a new layout which features the desired alignment constraint.
 208      *
 209      * @param bitAlignment the layout alignment constraint, expressed in bits.
 210      * @return a new layout which is the same as this layout, except for the alignment constraint associated to it.
 211      * @throws IllegalArgumentException if {@code bitAlignment} is not a power of two, or if it's less than than 8.
 212      */
 213     MemoryLayout withBitAlignment(long bitAlignment);
 214 
 215     /**


< prev index next >