Skip to content

Commit 7378260

Browse files
committed
Improve javadoc on WasmGCUnalignedUnsafeSupport#inWordRemainder
1 parent cc1c43d commit 7378260

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

web-image/src/com.oracle.svm.hosted.webimage/src/com/oracle/svm/hosted/webimage/wasmgc/WasmGCUnalignedUnsafeSupport.java

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -371,11 +371,15 @@ private static int getArrayIndexScale(JavaKind kind) {
371371
}
372372

373373
/**
374-
* Detect out of bounds access that is still within the same 4-byte word as the last element.
375-
* {@code jdk.internal.misc.Unsafe#compareAndExchangeByte} uses int accesses that are out of
376-
* bounds. For example, there might be an int access at the end of a byte array of length 5.
377-
* Such accesses are undefined behaviour. We may therefore ignore such accesses instead of
378-
* throwing an out-of-bounds exception.
374+
* Detect out of bounds access that is still within the same 4-byte aligned 4-byte word as the
375+
* last element. Such accesses are usually undefined behaviour, but to not produce unexpected
376+
* behavior (i.e. a crash), out of bounds accesses where this method returns {@code true} should
377+
* not crash and just return an arbitrary value and ignore any writes.
378+
* <p>
379+
* {@code jdk.internal.misc.Unsafe#compareAndExchangeByte} uses int accesses that may go out of
380+
* bounds and does not expect a crash in that case, though it ignores the out-of-bounds bytes.
381+
* For example, there might be an int access at the first element of a 1-element byte array.
382+
*
379383
*/
380384
private static boolean inWordRemainder(Object o, long offset) {
381385
int scaledOffset = getScaledOffset(o, offset);

0 commit comments

Comments
 (0)