Skip to content

Commit a8df132

Browse files
authored
Merge pull request #88 from OpenHFT/x.26
X.26
2 parents 008585e + 43fcaf2 commit a8df132

16 files changed

+65
-27
lines changed

.mvn/wrapper/MavenWrapperDownloader.java

-1
Original file line numberDiff line numberDiff line change
@@ -113,5 +113,4 @@ protected PasswordAuthentication getPasswordAuthentication() {
113113
fos.close();
114114
rbc.close();
115115
}
116-
117116
}

pom.xml

+37-4
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,13 @@
2020
<parent>
2121
<groupId>net.openhft</groupId>
2222
<artifactId>java-parent-pom</artifactId>
23-
<version>1.1.36</version>
23+
<version>1.26.0</version>
2424
<relativePath />
2525
</parent>
2626

2727
<modelVersion>4.0.0</modelVersion>
2828
<artifactId>zero-allocation-hashing</artifactId>
29-
<version>0.17-SNAPSHOT</version>
29+
<version>0.26ea0-SNAPSHOT</version>
3030
<name>Zero-allocation Hashing</name>
3131
<description>Zero-allocation implementations of fast non-cryptographic hash functions
3232
for byte sequences or blocks of memory</description>
@@ -206,6 +206,7 @@
206206

207207
<plugin>
208208
<artifactId>maven-source-plugin</artifactId>
209+
<version>3.2.1</version>
209210
<executions>
210211
<execution>
211212
<id>attach-sources</id>
@@ -331,7 +332,7 @@
331332
<profile>
332333
<id>jdk9+-profile</id>
333334
<activation>
334-
<jdk>[9,)</jdk>
335+
<jdk>[9,21)</jdk>
335336
</activation>
336337
<properties>
337338
<maven.compiler.release>${project.target.release}</maven.compiler.release>
@@ -355,7 +356,39 @@
355356
</plugins>
356357
</build>
357358
</profile>
358-
359+
<profile>
360+
<id>jdk21-profile</id>
361+
<activation>
362+
<jdk>[21,)</jdk>
363+
</activation>
364+
<properties>
365+
<maven.compiler.release>8</maven.compiler.release>
366+
</properties>
367+
<build>
368+
<plugins>
369+
<plugin>
370+
<artifactId>maven-compiler-plugin</artifactId>
371+
<configuration>
372+
<failOnWarning>false</failOnWarning>
373+
</configuration>
374+
</plugin>
375+
<plugin>
376+
<artifactId>maven-surefire-plugin</artifactId>
377+
<executions>
378+
<execution>
379+
<id>test-without-compact-string</id>
380+
<goals>
381+
<goal>test</goal>
382+
</goals>
383+
<configuration>
384+
<argLine>@{argLine} -XX:-CompactStrings ${jvm.requiredArgs}</argLine>
385+
</configuration>
386+
</execution>
387+
</executions>
388+
</plugin>
389+
</plugins>
390+
</build>
391+
</profile>
359392
<profile>
360393
<id>sonar</id>
361394
<build>

src/main/java/net/openhft/hashing/CityAndFarmHash_1_1.java

-1
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,6 @@ static LongHashFunction asLongHashFunctionWithTwoSeeds(long seed0, long seed1) {
320320
return new AsLongHashFunctionSeeded(seed0, seed1);
321321
}
322322

323-
324323
// FarmHash
325324

326325
private static <T> long naHashLen33To64(Access<T> access, T in, long off, long len) {

src/main/java/net/openhft/hashing/Maths.java

+26-6
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,24 @@
22

33
import org.jetbrains.annotations.NotNull;
44

5+
import java.lang.invoke.MethodHandle;
6+
import java.lang.invoke.MethodHandles;
7+
import java.lang.reflect.Method;
8+
59
class Maths {
610
@NotNull
711
private static final Maths INSTANCE;
812

913
static {
10-
boolean hasMultiplyHigh = true;
14+
Maths maths = null;
1115
try {
12-
Math.multiplyHigh(0, 0);
16+
Method multiplyHigh = Math.class.getDeclaredMethod("multiplyHigh", int.class, int.class);
17+
MethodHandle multiplyHighMH = MethodHandles.lookup().unreflect(multiplyHigh);
18+
maths = new MathsJDK9(multiplyHighMH);
1319
} catch (final Throwable ignore) {
14-
hasMultiplyHigh = false;
20+
maths = new Maths();
1521
}
16-
INSTANCE = hasMultiplyHigh ? new MathsJDK9() : new Maths();
22+
INSTANCE = maths;
1723
}
1824

1925
public static long unsignedLongMulXorFold(final long lhs, final long rhs) {
@@ -62,16 +68,30 @@ long unsignedLongMulHighImp(final long lhs, final long rhs) {
6268
}
6369

6470
class MathsJDK9 extends Maths {
71+
private final MethodHandle multiplyHighMH;
72+
73+
public MathsJDK9(MethodHandle multiplyHighMH) {
74+
this.multiplyHighMH = multiplyHighMH;
75+
}
76+
6577
// Math.multiplyHigh() is intrinsified from JDK 10. But JDK 9 is out of life, we always prefer
6678
// this version to the scalar one.
6779
@Override
6880
long unsignedLongMulXorFoldImp(final long lhs, final long rhs) {
69-
final long upper = Math.multiplyHigh(lhs, rhs) + ((lhs >> 63) & rhs) + ((rhs >> 63) & lhs);
81+
final long upper = invokeExact(lhs, rhs) + ((lhs >> 63) & rhs) + ((rhs >> 63) & lhs);
7082
final long lower = lhs * rhs;
7183
return lower ^ upper;
7284
}
7385
@Override
7486
long unsignedLongMulHighImp(final long lhs, final long rhs) {
75-
return Math.multiplyHigh(lhs, rhs) + ((lhs >> 63) & rhs) + ((rhs >> 63) & lhs);
87+
return invokeExact(lhs, rhs) + ((lhs >> 63) & rhs) + ((rhs >> 63) & lhs);
88+
}
89+
90+
private long invokeExact(long lhs, long rhs) {
91+
try {
92+
return (long) multiplyHighMH.invokeExact(lhs, rhs);
93+
} catch (Throwable e) {
94+
throw new AssertionError(e);
95+
}
7696
}
7797
}

src/main/java/net/openhft/hashing/MurmurHash_3.java

-1
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,6 @@ private static long finalize(long length, long h1, long h2, @Nullable long[] res
182182
h1 = fmix64(h1);
183183
h2 = fmix64(h2);
184184

185-
186185
if (null != result) {
187186
h1 += h2;
188187
result[0] = h1;

src/test/java/net/openhft/hashing/City64_1_1_Test.java

-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ public void testCityWithOneSeed() {
5151
test(LongHashFunction.city_1_1(0L, 0L), HASHES_OF_LOOPING_BYTES_WITH_SEEDS_0_0);
5252
}
5353

54-
5554
public void test(LongHashFunction city, long[] hashesOfLoopingBytes) {
5655
byte[] data = new byte[len];
5756
for (int j = 0; j < data.length; j++) {

src/test/java/net/openhft/hashing/FarmHashTest.java

-1
Original file line numberDiff line numberDiff line change
@@ -59,5 +59,4 @@ public void testNa() {
5959
LongHashFunctionTest.test(f, data, f.hashBytes(data));
6060
}
6161
}
62-
6362
}

src/test/java/net/openhft/hashing/LongHashFunctionTest.java

-1
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,6 @@ private static void testArrays(LongHashFunction f, byte[] data, long eh, int len
122122
System.arraycopy(shorts, 0, shorts2, 1, shortLen);
123123
assertEquals("short array off len", eh, f.hashShorts(shorts2, 1, shortLen));
124124

125-
126125
char[] chars = new char[shortLen];
127126
bb.asCharBuffer().get(chars);
128127
assertEquals("char array", eh, f.hashChars(chars));

src/test/java/net/openhft/hashing/LongTupleHashFunctionTest.java

-1
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,6 @@ private static void testArrays(LongTupleHashFunction f, byte[] data, long[] eh,
158158
System.arraycopy(shorts, 0, shorts2, 1, shortLen);
159159
assertArrayEquals("short array off len", eh, f.hashShorts(shorts2, 1, shortLen));
160160

161-
162161
char[] chars = new char[shortLen];
163162
bb.asCharBuffer().get(chars);
164163
assertArrayEquals("char array", eh, f.hashChars(chars));

src/test/java/net/openhft/hashing/MetroHashTest.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ public static Collection<Object[]> data() {
2222
@Parameterized.Parameter
2323
public int len;
2424

25-
2625
@Test
2726
public void testMetroWithoutSeeds() {
2827
test(LongHashFunction.metro(), HASHES_OF_LOOPING_BYTES_WITHOUT_SEED);
@@ -2123,4 +2122,4 @@ public void test(LongHashFunction metro, long[] hashesOfLoopingBytes) {
21232122
2937352060494234522L,
21242123
-2470412390340197582L
21252124
};
2126-
}
2125+
}

src/test/java/net/openhft/hashing/MurmurHash3Test.java

-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616

1717
package net.openhft.hashing;
1818

19-
2019
import com.google.common.hash.HashFunction;
2120
import com.google.common.hash.Hashing;
2221
import org.junit.Test;

src/test/java/net/openhft/hashing/OriginalFarmHashTest.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,6 @@ static int testUo(int offset, int len, int expectedIndex) {
133133
return expectedIndex;
134134
}
135135

136-
137136
@Test
138137
public void testUoGo() {
139138
for (Object[] g : GOLDEN_64) {
@@ -1268,7 +1267,7 @@ public void testUoGo() {
12681267
4144237690L, 3350490823L,
12691268
4166253320L, 2747410691L,
12701269
};
1271-
1270+
12721271
static final long[] UO_EXPECTED = {
12731272
3277735313L, 2681724312L,
12741273
2598464059L, 797982799L,

src/test/java/net/openhft/hashing/WyHashTest.java

-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ public void testWyHasWithOneSeed() {
3131
test(LongHashFunction.wy_3(42L), HASHES_OF_LOOPING_BYTES_WITH_SEED_42);
3232
}
3333

34-
3534
public void test(LongHashFunction wyHash, long[] hashesOfLoopingBytes) {
3635
byte[] data = new byte[len];
3736
for (int j = 0; j < data.length; j++) {

src/test/java/net/openhft/hashing/XXH128Test.java

-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@ public void test(LongTupleHashFunction h, LongHashFunction hl, long[][] hashesOf
6161
LongHashFunctionTest.test(hl, data, hashesOfLoopingBytes[len][0]);
6262
}
6363
}
64-
6564
/**
6665
* Test data is output of the following program with xxh3 implementation
6766
* from https://github.com/Cyan4973/xxHash

src/test/java/net/openhft/hashing/XXH3Test.java

-2
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ public void testXXH3WithOneSeed() {
5252
test(LongHashFunction.xx3(42L), XXH3Test_HASHES.HASHES_OF_LOOPING_BYTES_WITH_SEED_42);
5353
}
5454

55-
5655
public void test(LongHashFunction h, long[] hashesOfLoopingBytes) {
5756
byte[] data = new byte[len];
5857
for (int j = 0; j < data.length; j++) {
@@ -61,7 +60,6 @@ public void test(LongHashFunction h, long[] hashesOfLoopingBytes) {
6160
LongHashFunctionTest.test(h, data, hashesOfLoopingBytes[len]);
6261
}
6362
}
64-
6563
/**
6664
* Test data is output of the following program with xxh3 implementation
6765
* from https://github.com/Cyan4973/xxHash

src/test/java/net/openhft/hashing/XxHashTest.java

-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ public void testCityWithOneSeed() {
4848
test(LongHashFunction.xx(42L), HASHES_OF_LOOPING_BYTES_WITH_SEED_42);
4949
}
5050

51-
5251
public void test(LongHashFunction city, long[] hashesOfLoopingBytes) {
5352
byte[] data = new byte[len];
5453
for (int j = 0; j < data.length; j++) {

0 commit comments

Comments
 (0)