Skip to content

Commit

Permalink
Validate expected Matrix4f field offsets
Browse files Browse the repository at this point in the history
so that we can opt-out of the fast memory copies when it would be disallowed because of unexpected class layout.
  • Loading branch information
httpdigest committed Jul 9, 2016
1 parent ae18a5a commit db1639e
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/org/joml/MemUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -1012,6 +1012,15 @@ static final class MemUtilUnsafe extends MemUtil {
ADDRESS = UNSAFE.objectFieldOffset(getDeclaredField(Buffer.class, "address")); //$NON-NLS-1$
Field f = Matrix4f.class.getDeclaredField("m00");
m00FieldOffset = UNSAFE.objectFieldOffset(f);
// Validate expected field offsets
for (int i = 1; i < 16; i++) {
int c = i / 4;
int r = i % 4;
f = Matrix4f.class.getDeclaredField("m" + c + r);
long offset = UNSAFE.objectFieldOffset(f);
if (offset != m00FieldOffset + i * 4)
throw new UnsupportedOperationException();
}
// Check if we can use object field offset/address put/get methods
Unsafe.class.getDeclaredMethod("putLong", new Class[] {Object.class, long.class, long.class});
Unsafe.class.getDeclaredMethod("getLongVolatile", new Class[] {Object.class, long.class});
Expand Down

0 comments on commit db1639e

Please sign in to comment.