Skip to content

Commit 6caf5b0

Browse files
authored
Merge branch 'apache:main' into fst-streamline
2 parents fdc23e3 + 382aa54 commit 6caf5b0

File tree

21 files changed

+769
-390
lines changed

21 files changed

+769
-390
lines changed

gradle/testing/randomization.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ allprojects {
6767
// seed, repetition and amplification.
6868
[propName: 'tests.seed', value: { -> rootSeed }, description: "Sets the master randomization seed."],
6969
[propName: 'tests.iters', value: null, description: "Duplicate (re-run) each test case N times."],
70-
[propName: 'tests.multiplier', value: 1, description: "Value multiplier for randomized tests."],
70+
[propName: 'tests.multiplier', value: null, description: "Value multiplier for randomized tests."],
7171
[propName: 'tests.maxfailures', value: null, description: "Skip tests after a given number of failures."],
7272
[propName: 'tests.timeoutSuite', value: null, description: "Timeout (in millis) for an entire suite."],
7373
[propName: 'tests.failfast', value: "false", description: "Stop the build early on failure.", buildOnly: true],

lucene/CHANGES.txt

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -200,8 +200,8 @@ Improvements
200200
* GITHUB#12677: Better detect vector module in non-default setups (e.g., custom module layers).
201201
(Uwe Schindler)
202202

203-
* GITHUB#12634, GITHUB#12632, GITHUB#12680, GITHUB#12681, GITHUB#12731: Speed up Panama vector support
204-
and test improvements. (Uwe Schindler, Robert Muir)
203+
* GITHUB#12634, GITHUB#12632, GITHUB#12680, GITHUB#12681, GITHUB#12731, GITHUB#12737: Speed up
204+
Panama vector support and test improvements. (Uwe Schindler, Robert Muir)
205205

206206
* GITHUB#12586: Remove over-counting of deleted terms. (Guo Feng)
207207

@@ -210,6 +210,9 @@ Improvements
210210

211211
* GITHUB#12689: TaskExecutor to cancel all tasks on exception to avoid needless computation. (Luca Cavanna)
212212

213+
* GITHUB#12754: Refactor lookup of Hotspot VM options and do not initialize constants with NULL
214+
if SecurityManager prevents access. (Uwe Schindler)
215+
213216
Optimizations
214217
---------------------
215218
* GITHUB#12183: Make TermStates#build concurrent. (Shubham Chaudhary)
@@ -264,6 +267,8 @@ Changes in runtime behavior
264267
* GITHUB#12569: Prevent concurrent tasks from parallelizing execution further which could cause deadlock
265268
(Luca Cavanna)
266269

270+
* GITHUB#12765: Disable vectorization on VMs that are not Hotspot-based. (Uwe Schindler, Robert Muir)
271+
267272
Bug Fixes
268273
---------------------
269274

@@ -285,6 +290,9 @@ Bug Fixes
285290
Build
286291
---------------------
287292

293+
* GITHUB#12752: tests.multiplier could be omitted in test failure reproduce lines (esp. in
294+
nightly mode). (Dawid Weiss)
295+
288296
* GITHUB#12742: JavaCompile tasks may be in up-to-date state when modular dependencies have changed
289297
leading to odd runtime errors (Chris Hostetter, Dawid Weiss)
290298

lucene/analysis/common/src/tools/java/org/apache/lucene/analysis/standard/GenerateJflexTLDMacros.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import java.io.InputStreamReader;
2222
import java.io.OutputStreamWriter;
2323
import java.io.Writer;
24+
import java.net.URI;
2425
import java.net.URL;
2526
import java.net.URLConnection;
2627
import java.nio.charset.StandardCharsets;
@@ -111,7 +112,7 @@ public static void main(String... args) throws Exception {
111112

112113
public GenerateJflexTLDMacros(String tldFileURL, String jflexFile, String tldListFile)
113114
throws Exception {
114-
this.tldFileURL = new URL(tldFileURL);
115+
this.tldFileURL = URI.create(tldFileURL).toURL();
115116
this.jflexMacroFile = Paths.get(jflexFile);
116117
this.tldListFile = Paths.get(tldListFile);
117118
}

lucene/analysis/icu/src/tools/java/org/apache/lucene/analysis/icu/GenerateUTR30DataFiles.java

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import java.io.OutputStream;
2828
import java.io.OutputStreamWriter;
2929
import java.io.Writer;
30+
import java.net.URI;
3031
import java.net.URL;
3132
import java.net.URLConnection;
3233
import java.nio.charset.StandardCharsets;
@@ -155,19 +156,19 @@ private static void expandDataFileRules(Path file) throws IOException {
155156
}
156157

157158
private static void getNFKCDataFilesFromIcuProject(String releaseTag) throws IOException {
158-
URL icuTagsURL = new URL(ICU_GIT_TAG_URL + "/");
159-
URL icuReleaseTagURL = new URL(icuTagsURL, releaseTag + "/");
160-
URL norm2url = new URL(icuReleaseTagURL, ICU_DATA_NORM2_PATH + "/");
159+
URI icuTagsURI = URI.create(ICU_GIT_TAG_URL + "/");
160+
URI icuReleaseTagURI = icuTagsURI.resolve(releaseTag + "/");
161+
URI norm2uri = icuReleaseTagURI.resolve(ICU_DATA_NORM2_PATH + "/");
161162

162163
System.err.print("Downloading " + NFKC_TXT + " ... ");
163-
download(new URL(norm2url, NFKC_TXT), NFKC_TXT);
164+
download(norm2uri.resolve(NFKC_TXT), NFKC_TXT);
164165
System.err.println("done.");
165166
System.err.print("Downloading " + NFKC_CF_TXT + " ... ");
166-
download(new URL(norm2url, NFKC_CF_TXT), NFKC_CF_TXT);
167+
download(norm2uri.resolve(NFKC_CF_TXT), NFKC_CF_TXT);
167168
System.err.println("done.");
168169

169170
System.err.print("Downloading " + NFKC_CF_TXT + " and making diacritic rules one-way ... ");
170-
URLConnection connection = openConnection(new URL(norm2url, NFC_TXT));
171+
URLConnection connection = openConnection(norm2uri.resolve(NFC_TXT).toURL());
171172
try (BufferedReader reader =
172173
new BufferedReader(
173174
new InputStreamReader(connection.getInputStream(), StandardCharsets.UTF_8));
@@ -210,8 +211,8 @@ private static void getNFKCDataFilesFromIcuProject(String releaseTag) throws IOE
210211
System.err.println("done.");
211212
}
212213

213-
private static void download(URL url, String outputFile) throws IOException {
214-
final URLConnection connection = openConnection(url);
214+
private static void download(URI uri, String outputFile) throws IOException {
215+
final URLConnection connection = openConnection(uri.toURL());
215216
try (InputStream inputStream = connection.getInputStream();
216217
OutputStream outputStream = Files.newOutputStream(Path.of(outputFile))) {
217218
inputStream.transferTo(outputStream);

lucene/core/src/java/org/apache/lucene/internal/vectorization/DefaultVectorUtilSupport.java

Lines changed: 96 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -17,72 +17,46 @@
1717

1818
package org.apache.lucene.internal.vectorization;
1919

20+
import org.apache.lucene.util.Constants;
21+
import org.apache.lucene.util.SuppressForbidden;
22+
2023
final class DefaultVectorUtilSupport implements VectorUtilSupport {
2124

2225
DefaultVectorUtilSupport() {}
2326

27+
// the way FMA should work! if available use it, otherwise fall back to mul/add
28+
@SuppressForbidden(reason = "Uses FMA only where fast and carefully contained")
29+
private static float fma(float a, float b, float c) {
30+
if (Constants.HAS_FAST_SCALAR_FMA) {
31+
return Math.fma(a, b, c);
32+
} else {
33+
return a * b + c;
34+
}
35+
}
36+
2437
@Override
2538
public float dotProduct(float[] a, float[] b) {
2639
float res = 0f;
27-
/*
28-
* If length of vector is larger than 8, we use unrolled dot product to accelerate the
29-
* calculation.
30-
*/
31-
int i;
32-
for (i = 0; i < a.length % 8; i++) {
33-
res += b[i] * a[i];
34-
}
35-
if (a.length < 8) {
36-
return res;
37-
}
38-
for (; i + 31 < a.length; i += 32) {
39-
res +=
40-
b[i + 0] * a[i + 0]
41-
+ b[i + 1] * a[i + 1]
42-
+ b[i + 2] * a[i + 2]
43-
+ b[i + 3] * a[i + 3]
44-
+ b[i + 4] * a[i + 4]
45-
+ b[i + 5] * a[i + 5]
46-
+ b[i + 6] * a[i + 6]
47-
+ b[i + 7] * a[i + 7];
48-
res +=
49-
b[i + 8] * a[i + 8]
50-
+ b[i + 9] * a[i + 9]
51-
+ b[i + 10] * a[i + 10]
52-
+ b[i + 11] * a[i + 11]
53-
+ b[i + 12] * a[i + 12]
54-
+ b[i + 13] * a[i + 13]
55-
+ b[i + 14] * a[i + 14]
56-
+ b[i + 15] * a[i + 15];
57-
res +=
58-
b[i + 16] * a[i + 16]
59-
+ b[i + 17] * a[i + 17]
60-
+ b[i + 18] * a[i + 18]
61-
+ b[i + 19] * a[i + 19]
62-
+ b[i + 20] * a[i + 20]
63-
+ b[i + 21] * a[i + 21]
64-
+ b[i + 22] * a[i + 22]
65-
+ b[i + 23] * a[i + 23];
66-
res +=
67-
b[i + 24] * a[i + 24]
68-
+ b[i + 25] * a[i + 25]
69-
+ b[i + 26] * a[i + 26]
70-
+ b[i + 27] * a[i + 27]
71-
+ b[i + 28] * a[i + 28]
72-
+ b[i + 29] * a[i + 29]
73-
+ b[i + 30] * a[i + 30]
74-
+ b[i + 31] * a[i + 31];
40+
int i = 0;
41+
42+
// if the array is big, unroll it
43+
if (a.length > 32) {
44+
float acc1 = 0;
45+
float acc2 = 0;
46+
float acc3 = 0;
47+
float acc4 = 0;
48+
int upperBound = a.length & ~(4 - 1);
49+
for (; i < upperBound; i += 4) {
50+
acc1 = fma(a[i], b[i], acc1);
51+
acc2 = fma(a[i + 1], b[i + 1], acc2);
52+
acc3 = fma(a[i + 2], b[i + 2], acc3);
53+
acc4 = fma(a[i + 3], b[i + 3], acc4);
54+
}
55+
res += acc1 + acc2 + acc3 + acc4;
7556
}
76-
for (; i + 7 < a.length; i += 8) {
77-
res +=
78-
b[i + 0] * a[i + 0]
79-
+ b[i + 1] * a[i + 1]
80-
+ b[i + 2] * a[i + 2]
81-
+ b[i + 3] * a[i + 3]
82-
+ b[i + 4] * a[i + 4]
83-
+ b[i + 5] * a[i + 5]
84-
+ b[i + 6] * a[i + 6]
85-
+ b[i + 7] * a[i + 7];
57+
58+
for (; i < a.length; i++) {
59+
res = fma(a[i], b[i], res);
8660
}
8761
return res;
8862
}
@@ -92,50 +66,80 @@ public float cosine(float[] a, float[] b) {
9266
float sum = 0.0f;
9367
float norm1 = 0.0f;
9468
float norm2 = 0.0f;
95-
int dim = a.length;
69+
int i = 0;
9670

97-
for (int i = 0; i < dim; i++) {
98-
float elem1 = a[i];
99-
float elem2 = b[i];
100-
sum += elem1 * elem2;
101-
norm1 += elem1 * elem1;
102-
norm2 += elem2 * elem2;
71+
// if the array is big, unroll it
72+
if (a.length > 32) {
73+
float sum1 = 0;
74+
float sum2 = 0;
75+
float norm1_1 = 0;
76+
float norm1_2 = 0;
77+
float norm2_1 = 0;
78+
float norm2_2 = 0;
79+
80+
int upperBound = a.length & ~(2 - 1);
81+
for (; i < upperBound; i += 2) {
82+
// one
83+
sum1 = fma(a[i], b[i], sum1);
84+
norm1_1 = fma(a[i], a[i], norm1_1);
85+
norm2_1 = fma(b[i], b[i], norm2_1);
86+
87+
// two
88+
sum2 = fma(a[i + 1], b[i + 1], sum2);
89+
norm1_2 = fma(a[i + 1], a[i + 1], norm1_2);
90+
norm2_2 = fma(b[i + 1], b[i + 1], norm2_2);
91+
}
92+
sum += sum1 + sum2;
93+
norm1 += norm1_1 + norm1_2;
94+
norm2 += norm2_1 + norm2_2;
95+
}
96+
97+
for (; i < a.length; i++) {
98+
sum = fma(a[i], b[i], sum);
99+
norm1 = fma(a[i], a[i], norm1);
100+
norm2 = fma(b[i], b[i], norm2);
103101
}
104102
return (float) (sum / Math.sqrt((double) norm1 * (double) norm2));
105103
}
106104

107105
@Override
108106
public float squareDistance(float[] a, float[] b) {
109-
float squareSum = 0.0f;
110-
int dim = a.length;
111-
int i;
112-
for (i = 0; i + 8 <= dim; i += 8) {
113-
squareSum += squareDistanceUnrolled(a, b, i);
107+
float res = 0;
108+
int i = 0;
109+
110+
// if the array is big, unroll it
111+
if (a.length > 32) {
112+
float acc1 = 0;
113+
float acc2 = 0;
114+
float acc3 = 0;
115+
float acc4 = 0;
116+
117+
int upperBound = a.length & ~(4 - 1);
118+
for (; i < upperBound; i += 4) {
119+
// one
120+
float diff1 = a[i] - b[i];
121+
acc1 = fma(diff1, diff1, acc1);
122+
123+
// two
124+
float diff2 = a[i + 1] - b[i + 1];
125+
acc2 = fma(diff2, diff2, acc2);
126+
127+
// three
128+
float diff3 = a[i + 2] - b[i + 2];
129+
acc3 = fma(diff3, diff3, acc3);
130+
131+
// four
132+
float diff4 = a[i + 3] - b[i + 3];
133+
acc4 = fma(diff4, diff4, acc4);
134+
}
135+
res += acc1 + acc2 + acc3 + acc4;
114136
}
115-
for (; i < dim; i++) {
137+
138+
for (; i < a.length; i++) {
116139
float diff = a[i] - b[i];
117-
squareSum += diff * diff;
140+
res = fma(diff, diff, res);
118141
}
119-
return squareSum;
120-
}
121-
122-
private static float squareDistanceUnrolled(float[] v1, float[] v2, int index) {
123-
float diff0 = v1[index + 0] - v2[index + 0];
124-
float diff1 = v1[index + 1] - v2[index + 1];
125-
float diff2 = v1[index + 2] - v2[index + 2];
126-
float diff3 = v1[index + 3] - v2[index + 3];
127-
float diff4 = v1[index + 4] - v2[index + 4];
128-
float diff5 = v1[index + 5] - v2[index + 5];
129-
float diff6 = v1[index + 6] - v2[index + 6];
130-
float diff7 = v1[index + 7] - v2[index + 7];
131-
return diff0 * diff0
132-
+ diff1 * diff1
133-
+ diff2 * diff2
134-
+ diff3 * diff3
135-
+ diff4 * diff4
136-
+ diff5 * diff5
137-
+ diff6 * diff6
138-
+ diff7 * diff7;
142+
return res;
139143
}
140144

141145
@Override

lucene/core/src/java/org/apache/lucene/internal/vectorization/VectorizationProvider.java

Lines changed: 8 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@
2121
import java.lang.StackWalker.StackFrame;
2222
import java.lang.invoke.MethodHandles;
2323
import java.lang.invoke.MethodType;
24-
import java.security.AccessController;
25-
import java.security.PrivilegedAction;
2624
import java.util.Locale;
2725
import java.util.Objects;
2826
import java.util.Optional;
@@ -31,7 +29,7 @@
3129
import java.util.function.Predicate;
3230
import java.util.logging.Logger;
3331
import java.util.stream.Stream;
34-
import org.apache.lucene.util.SuppressForbidden;
32+
import org.apache.lucene.util.Constants;
3533
import org.apache.lucene.util.VectorUtil;
3634

3735
/**
@@ -113,6 +111,12 @@ static VectorizationProvider lookup(boolean testMode) {
113111
+ Locale.getDefault());
114112
return new DefaultVectorizationProvider();
115113
}
114+
// only use vector module with Hotspot VM
115+
if (!Constants.IS_HOTSPOT_VM) {
116+
LOG.warning(
117+
"Java runtime is not using Hotspot VM; Java vector incubator API can't be enabled.");
118+
return new DefaultVectorizationProvider();
119+
}
116120
// is the incubator module present and readable (JVM providers may to exclude them or it is
117121
// build with jlink)
118122
final var vectorMod = lookupVectorModule();
@@ -129,7 +133,7 @@ static VectorizationProvider lookup(boolean testMode) {
129133
"Vector bitsize and/or integer vectors enforcement; using default vectorization provider outside of testMode");
130134
return new DefaultVectorizationProvider();
131135
}
132-
if (isClientVM()) {
136+
if (Constants.IS_CLIENT_VM) {
133137
LOG.warning("C2 compiler is disabled; Java vector incubator API can't be enabled");
134138
return new DefaultVectorizationProvider();
135139
}
@@ -188,23 +192,6 @@ private static boolean isAffectedByJDK8301190() {
188192
&& !Objects.equals("I", "i".toUpperCase(Locale.getDefault()));
189193
}
190194

191-
@SuppressWarnings("removal")
192-
@SuppressForbidden(reason = "security manager")
193-
private static boolean isClientVM() {
194-
try {
195-
final PrivilegedAction<Boolean> action =
196-
() -> System.getProperty("java.vm.info", "").contains("emulated-client");
197-
return AccessController.doPrivileged(action);
198-
} catch (
199-
@SuppressWarnings("unused")
200-
SecurityException e) {
201-
LOG.warning(
202-
"SecurityManager denies permission to 'java.vm.info' system property, so state of C2 compiler can't be detected. "
203-
+ "In case of performance issues allow access to this property.");
204-
return false;
205-
}
206-
}
207-
208195
// add all possible callers here as FQCN:
209196
private static final Set<String> VALID_CALLERS = Set.of("org.apache.lucene.util.VectorUtil");
210197

0 commit comments

Comments
 (0)