@@ -267,6 +267,7 @@ public void set(ValueLayout.OfAddress layout, long offset, Addressable value) {
267267 @ CallerSensitive
268268 public char getAtIndex (ValueLayout .OfChar layout , long index ) {
269269 Reflection .ensureNativeAccess (Reflection .getCallerClass ());
270+ Utils .checkElementAlignment (layout , "Layout alignment greater than its size" );
270271 return NativeMemorySegmentImpl .EVERYTHING .get (layout , toRawLongValue () + (index * layout .byteSize ()));
271272 }
272273
@@ -275,6 +276,7 @@ public char getAtIndex(ValueLayout.OfChar layout, long index) {
275276 @ CallerSensitive
276277 public void setAtIndex (ValueLayout .OfChar layout , long index , char value ) {
277278 Reflection .ensureNativeAccess (Reflection .getCallerClass ());
279+ Utils .checkElementAlignment (layout , "Layout alignment greater than its size" );
278280 NativeMemorySegmentImpl .EVERYTHING .set (layout , toRawLongValue () + (index * layout .byteSize ()), value );
279281 }
280282
@@ -283,6 +285,7 @@ public void setAtIndex(ValueLayout.OfChar layout, long index, char value) {
283285 @ CallerSensitive
284286 public short getAtIndex (ValueLayout .OfShort layout , long index ) {
285287 Reflection .ensureNativeAccess (Reflection .getCallerClass ());
288+ Utils .checkElementAlignment (layout , "Layout alignment greater than its size" );
286289 return NativeMemorySegmentImpl .EVERYTHING .get (layout , toRawLongValue () + (index * layout .byteSize ()));
287290 }
288291
@@ -291,6 +294,7 @@ public short getAtIndex(ValueLayout.OfShort layout, long index) {
291294 @ CallerSensitive
292295 public void setAtIndex (ValueLayout .OfShort layout , long index , short value ) {
293296 Reflection .ensureNativeAccess (Reflection .getCallerClass ());
297+ Utils .checkElementAlignment (layout , "Layout alignment greater than its size" );
294298 NativeMemorySegmentImpl .EVERYTHING .set (layout , toRawLongValue () + (index * layout .byteSize ()), value );
295299 }
296300
@@ -299,6 +303,7 @@ public void setAtIndex(ValueLayout.OfShort layout, long index, short value) {
299303 @ CallerSensitive
300304 public int getAtIndex (ValueLayout .OfInt layout , long index ) {
301305 Reflection .ensureNativeAccess (Reflection .getCallerClass ());
306+ Utils .checkElementAlignment (layout , "Layout alignment greater than its size" );
302307 return NativeMemorySegmentImpl .EVERYTHING .get (layout , toRawLongValue () + (index * layout .byteSize ()));
303308 }
304309
@@ -307,6 +312,7 @@ public int getAtIndex(ValueLayout.OfInt layout, long index) {
307312 @ CallerSensitive
308313 public void setAtIndex (ValueLayout .OfInt layout , long index , int value ) {
309314 Reflection .ensureNativeAccess (Reflection .getCallerClass ());
315+ Utils .checkElementAlignment (layout , "Layout alignment greater than its size" );
310316 NativeMemorySegmentImpl .EVERYTHING .set (layout , toRawLongValue () + (index * layout .byteSize ()), value );
311317 }
312318
@@ -315,6 +321,7 @@ public void setAtIndex(ValueLayout.OfInt layout, long index, int value) {
315321 @ CallerSensitive
316322 public float getAtIndex (ValueLayout .OfFloat layout , long index ) {
317323 Reflection .ensureNativeAccess (Reflection .getCallerClass ());
324+ Utils .checkElementAlignment (layout , "Layout alignment greater than its size" );
318325 return NativeMemorySegmentImpl .EVERYTHING .get (layout , toRawLongValue () + (index * layout .byteSize ()));
319326 }
320327
@@ -323,6 +330,7 @@ public float getAtIndex(ValueLayout.OfFloat layout, long index) {
323330 @ CallerSensitive
324331 public void setAtIndex (ValueLayout .OfFloat layout , long index , float value ) {
325332 Reflection .ensureNativeAccess (Reflection .getCallerClass ());
333+ Utils .checkElementAlignment (layout , "Layout alignment greater than its size" );
326334 NativeMemorySegmentImpl .EVERYTHING .set (layout , toRawLongValue () + (index * layout .byteSize ()), value );
327335 }
328336
@@ -331,6 +339,7 @@ public void setAtIndex(ValueLayout.OfFloat layout, long index, float value) {
331339 @ CallerSensitive
332340 public long getAtIndex (ValueLayout .OfLong layout , long index ) {
333341 Reflection .ensureNativeAccess (Reflection .getCallerClass ());
342+ Utils .checkElementAlignment (layout , "Layout alignment greater than its size" );
334343 return NativeMemorySegmentImpl .EVERYTHING .get (layout , toRawLongValue () + (index * layout .byteSize ()));
335344 }
336345
@@ -339,6 +348,7 @@ public long getAtIndex(ValueLayout.OfLong layout, long index) {
339348 @ CallerSensitive
340349 public void setAtIndex (ValueLayout .OfLong layout , long index , long value ) {
341350 Reflection .ensureNativeAccess (Reflection .getCallerClass ());
351+ Utils .checkElementAlignment (layout , "Layout alignment greater than its size" );
342352 NativeMemorySegmentImpl .EVERYTHING .set (layout , toRawLongValue () + (index * layout .byteSize ()), value );
343353 }
344354
@@ -347,6 +357,7 @@ public void setAtIndex(ValueLayout.OfLong layout, long index, long value) {
347357 @ CallerSensitive
348358 public double getAtIndex (ValueLayout .OfDouble layout , long index ) {
349359 Reflection .ensureNativeAccess (Reflection .getCallerClass ());
360+ Utils .checkElementAlignment (layout , "Layout alignment greater than its size" );
350361 return NativeMemorySegmentImpl .EVERYTHING .get (layout , toRawLongValue () + (index * layout .byteSize ()));
351362 }
352363
@@ -355,6 +366,7 @@ public double getAtIndex(ValueLayout.OfDouble layout, long index) {
355366 @ CallerSensitive
356367 public void setAtIndex (ValueLayout .OfDouble layout , long index , double value ) {
357368 Reflection .ensureNativeAccess (Reflection .getCallerClass ());
369+ Utils .checkElementAlignment (layout , "Layout alignment greater than its size" );
358370 NativeMemorySegmentImpl .EVERYTHING .set (layout , toRawLongValue () + (index * layout .byteSize ()), value );
359371 }
360372
@@ -363,6 +375,7 @@ public void setAtIndex(ValueLayout.OfDouble layout, long index, double value) {
363375 @ CallerSensitive
364376 public MemoryAddress getAtIndex (ValueLayout .OfAddress layout , long index ) {
365377 Reflection .ensureNativeAccess (Reflection .getCallerClass ());
378+ Utils .checkElementAlignment (layout , "Layout alignment greater than its size" );
366379 return NativeMemorySegmentImpl .EVERYTHING .get (layout , toRawLongValue () + (index * layout .byteSize ()));
367380 }
368381
@@ -371,6 +384,7 @@ public MemoryAddress getAtIndex(ValueLayout.OfAddress layout, long index) {
371384 @ CallerSensitive
372385 public void setAtIndex (ValueLayout .OfAddress layout , long index , Addressable value ) {
373386 Reflection .ensureNativeAccess (Reflection .getCallerClass ());
387+ Utils .checkElementAlignment (layout , "Layout alignment greater than its size" );
374388 NativeMemorySegmentImpl .EVERYTHING .set (layout , toRawLongValue () + (index * layout .byteSize ()), value .address ());
375389 }
376390}
0 commit comments