diff --git a/calculate_average_gamlerhart.sh b/calculate_average_gamlerhart.sh index c52a25b..7427ea6 100755 --- a/calculate_average_gamlerhart.sh +++ b/calculate_average_gamlerhart.sh @@ -15,5 +15,5 @@ # limitations under the License. # -JAVA_OPTS="--enable-preview --add-modules=jdk.incubator.vector" +JAVA_OPTS="--enable-preview --add-modules=jdk.incubator.vector -XX:+UnlockExperimentalVMOptions -XX:+UseEpsilonGC -Xmx512m -Xlog:all=error" java $JAVA_OPTS --class-path target/average-1.0.0-SNAPSHOT.jar dev.morling.onebrc.CalculateAverage_gamlerhart diff --git a/src/main/java/dev/morling/onebrc/CalculateAverage_gamlerhart.java b/src/main/java/dev/morling/onebrc/CalculateAverage_gamlerhart.java index 5d0a4bd..4d44494 100644 --- a/src/main/java/dev/morling/onebrc/CalculateAverage_gamlerhart.java +++ b/src/main/java/dev/morling/onebrc/CalculateAverage_gamlerhart.java @@ -31,8 +31,7 @@ import java.util.stream.Collectors; import static java.lang.Double.doubleToRawLongBits; import static java.lang.Double.longBitsToDouble; -import static java.lang.foreign.ValueLayout.JAVA_BYTE; -import static java.lang.foreign.ValueLayout.JAVA_LONG_UNALIGNED; +import static java.lang.foreign.ValueLayout.*; /** * Broad experiments in this implementation: @@ -242,7 +241,7 @@ public class CalculateAverage_gamlerhart { private boolean isSameEntry(MemorySegment file, long slotEntry, long pos, int len) { long keyPos = (slotEntry & MASK_POS) >> SHIFT_POS; int keyLen = (int) (slotEntry & MASK_LEN); - var isSame = isSame(file, keyPos, pos, len); + var isSame = len == keyLen && isSame(file, keyPos, pos, len); return isSame; } @@ -251,8 +250,8 @@ public class CalculateAverage_gamlerhart { var i1len = i1 + vecLen; var i2len = i2 + vecLen; if (len < vecLen && i1len <= file.byteSize() && i2len <= file.byteSize()) { - var v1 = byteVec.fromMemorySegment(file, i1, ByteOrder.BIG_ENDIAN); - var v2 = byteVec.fromMemorySegment(file, i2, ByteOrder.BIG_ENDIAN); + var v1 = byteVec.fromMemorySegment(file, i1, ByteOrder.nativeOrder()); + var v2 = byteVec.fromMemorySegment(file, i2, ByteOrder.nativeOrder()); var isTrue = v1.compare(VectorOperators.EQ, v2, allTrue.indexInRange(0, len)); return isTrue.trueCount() == len; }