Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,14 @@ private static final class WaitState {
private final Map<Integer, WaitState> waitStates = new ConcurrentHashMap<>();
private final MemoryLimits limits;
private final MemorySegment reserved;
// Build the value layouts at compile time and use known JIT value for lookups instead of building object for each call.
private static final ValueLayout.OfInt INT_LE =
ValueLayout.JAVA_INT_UNALIGNED.withOrder(ByteOrder.LITTLE_ENDIAN);
private static final ValueLayout.OfLong LONG_LE =
ValueLayout.JAVA_LONG_UNALIGNED.withOrder(ByteOrder.LITTLE_ENDIAN);
private static final ValueLayout.OfShort SHORT_LE =
ValueLayout.JAVA_SHORT_UNALIGNED.withOrder(ByteOrder.LITTLE_ENDIAN);

private MemorySegment segment;
private int nPages;
private final long reservedSize;
Expand Down Expand Up @@ -281,8 +289,7 @@ public byte[] readBytes(int addr, int len) {
@Override
public void writeI32(int addr, int data) {
try {
segment.set(
ValueLayout.JAVA_INT_UNALIGNED.withOrder(ByteOrder.LITTLE_ENDIAN), addr, data);
segment.set(INT_LE, addr, data);
} catch (IndexOutOfBoundsException e) {
throw outOfBounds(addr);
}
Expand All @@ -291,8 +298,7 @@ public void writeI32(int addr, int data) {
@Override
public int readInt(int addr) {
try {
return segment.get(
ValueLayout.JAVA_INT_UNALIGNED.withOrder(ByteOrder.LITTLE_ENDIAN), addr);
return segment.get(INT_LE, addr);
} catch (IndexOutOfBoundsException e) {
throw outOfBounds(addr);
}
Expand All @@ -301,8 +307,7 @@ public int readInt(int addr) {
@Override
public void writeLong(int addr, long data) {
try {
segment.set(
ValueLayout.JAVA_LONG_UNALIGNED.withOrder(ByteOrder.LITTLE_ENDIAN), addr, data);
segment.set(LONG_LE, addr, data);
} catch (IndexOutOfBoundsException e) {
throw outOfBounds(addr);
}
Expand All @@ -311,8 +316,7 @@ public void writeLong(int addr, long data) {
@Override
public long readLong(int addr) {
try {
return segment.get(
ValueLayout.JAVA_LONG_UNALIGNED.withOrder(ByteOrder.LITTLE_ENDIAN), addr);
return segment.get(LONG_LE, addr);
} catch (IndexOutOfBoundsException e) {
throw outOfBounds(addr);
}
Expand All @@ -321,10 +325,7 @@ public long readLong(int addr) {
@Override
public void writeShort(int addr, short data) {
try {
segment.set(
ValueLayout.JAVA_SHORT_UNALIGNED.withOrder(ByteOrder.LITTLE_ENDIAN),
addr,
data);
segment.set(SHORT_LE, addr, data);
} catch (IndexOutOfBoundsException e) {
throw outOfBounds(addr);
}
Expand All @@ -333,8 +334,7 @@ public void writeShort(int addr, short data) {
@Override
public short readShort(int addr) {
try {
return segment.get(
ValueLayout.JAVA_SHORT_UNALIGNED.withOrder(ByteOrder.LITTLE_ENDIAN), addr);
return segment.get(SHORT_LE, addr);
} catch (IndexOutOfBoundsException e) {
throw outOfBounds(addr);
}
Expand Down
Loading