Skip to content
Merged
Show file tree
Hide file tree
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
3 changes: 3 additions & 0 deletions gradle/testing/randomization/policies/tests.policy
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ grant {
permission java.lang.RuntimePermission "getFileStoreAttributes";
permission java.lang.RuntimePermission "writeFileDescriptor";

// needed to check if C2 (implied by the presence of the CI env) is enabled
permission java.lang.RuntimePermission "getenv.CI";
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi Chris,
this env var isn't too useful as Jenkins does not set it. The logic to detect the CI availability is harder, but actually please remove the permission again, see below!

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Didn't know about it either. Will this work?
#12953

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes this works. Gradle enables Tiered compiler if Jenkins or GitHub is detected.

value: { -> propertyOrEnvOrDefault("tests.jvmargs", "TEST_JVM_ARGS", isCIBuild ? "" : "-XX:TieredStopAtLevel=1 -XX:+UseParallelGC -XX:ActiveProcessorCount=1") },


// TestLockFactoriesMultiJVM opens a random port on 127.0.0.1 (port 0 = ephemeral port range):
permission java.net.SocketPermission "127.0.0.1:0", "accept,listen,resolve";

Expand Down
21 changes: 21 additions & 0 deletions lucene/core/src/java/org/apache/lucene/util/MSBRadixSorter.java
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,16 @@ protected int getBucket(int i, int k) {
*
* @see #buildHistogram
*/
// This method, and its namesakes, have been manually split to work around a JVM crash.
// See https://github.com/apache/lucene/issues/12898
private int computeCommonPrefixLengthAndBuildHistogram(int from, int to, int k, int[] histogram) {
int commonPrefixLength = computeInitialCommonPrefixLength(from, k);
return computeCommonPrefixLengthAndBuildHistogramPart1(
from, to, k, histogram, commonPrefixLength);
}

// This method, and its namesakes, have been manually split to work around a JVM crash.
private int computeInitialCommonPrefixLength(int from, int k) {
final int[] commonPrefix = this.commonPrefix;
int commonPrefixLength = Math.min(commonPrefix.length, maxLength - k);
for (int j = 0; j < commonPrefixLength; ++j) {
Expand All @@ -224,7 +233,13 @@ private int computeCommonPrefixLengthAndBuildHistogram(int from, int to, int k,
break;
}
}
return commonPrefixLength;
}

// This method, and its namesakes, have been manually split to work around a JVM crash.
private int computeCommonPrefixLengthAndBuildHistogramPart1(
int from, int to, int k, int[] histogram, int commonPrefixLength) {
final int[] commonPrefix = this.commonPrefix;
int i;
outer:
for (i = from + 1; i < to; ++i) {
Expand All @@ -239,7 +254,13 @@ private int computeCommonPrefixLengthAndBuildHistogram(int from, int to, int k,
}
}
}
return computeCommonPrefixLengthAndBuildHistogramPart2(
from, to, k, histogram, commonPrefixLength, i);
}

// This method, and its namesakes, have been manually split to work around a JVM crash.
private int computeCommonPrefixLengthAndBuildHistogramPart2(
int from, int to, int k, int[] histogram, int commonPrefixLength, int i) {
if (i < to) {
// the loop got broken because there is no common prefix
assert commonPrefixLength == 0;
Expand Down
21 changes: 21 additions & 0 deletions lucene/core/src/java/org/apache/lucene/util/RadixSelector.java
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,16 @@ private int getBucket(int i, int k) {
*
* @see #buildHistogram
*/
// This method, and its namesakes, have been manually split to work around a JVM crash.
// See https://github.com/apache/lucene/issues/12898
private int computeCommonPrefixLengthAndBuildHistogram(int from, int to, int k, int[] histogram) {
int commonPrefixLength = computeInitialCommonPrefixLength(from, k);
return computeCommonPrefixLengthAndBuildHistogramPart1(
from, to, k, histogram, commonPrefixLength);
}

// This method, and its namesakes, have been manually split to work around a JVM crash.
private int computeInitialCommonPrefixLength(int from, int k) {
final int[] commonPrefix = this.commonPrefix;
int commonPrefixLength = Math.min(commonPrefix.length, maxLength - k);
for (int j = 0; j < commonPrefixLength; ++j) {
Expand All @@ -209,7 +218,13 @@ private int computeCommonPrefixLengthAndBuildHistogram(int from, int to, int k,
break;
}
}
return commonPrefixLength;
}

// This method, and its namesakes, have been manually split to work around a JVM crash.
private int computeCommonPrefixLengthAndBuildHistogramPart1(
int from, int to, int k, int[] histogram, int commonPrefixLength) {
final int[] commonPrefix = this.commonPrefix;
int i;
outer:
for (i = from + 1; i < to; ++i) {
Expand All @@ -226,7 +241,13 @@ private int computeCommonPrefixLengthAndBuildHistogram(int from, int to, int k,
}
}
}
return computeCommonPrefixLengthAndBuildHistogramPart2(
from, to, k, histogram, commonPrefixLength, i);
}

// This method, and its namesakes, have been manually split to work around a JVM crash.
private int computeCommonPrefixLengthAndBuildHistogramPart2(
int from, int to, int k, int[] histogram, int commonPrefixLength, int i) {
if (i < to) {
// the loop got broken because there is no common prefix
assert commonPrefixLength == 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,14 @@
package org.apache.lucene.util.bkd;

import java.io.IOException;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.util.Arrays;
import java.util.List;
import java.util.Set;
import org.apache.lucene.document.IntPoint;
import org.apache.lucene.document.SortedNumericDocValuesField;
import org.apache.lucene.index.IndexWriter;
import org.apache.lucene.index.PointValues.IntersectVisitor;
import org.apache.lucene.index.PointValues.Relation;
import org.apache.lucene.store.Directory;
Expand All @@ -28,6 +34,7 @@
import org.apache.lucene.tests.util.LuceneTestCase;
import org.apache.lucene.tests.util.TestUtil;
import org.apache.lucene.util.CollectionUtil;
import org.apache.lucene.util.SuppressForbidden;

public class TestDocIdsWriter extends LuceneTestCase {

Expand Down Expand Up @@ -150,4 +157,28 @@ public Relation compare(byte[] minPackedValue, byte[] maxPackedValue) {
}
dir.deleteFile("tmp");
}

// This simple test tickles a JVM C2 JIT crash on JDK's less than 21.0.1
// Crashes only when run with C2, so with the environment variable `CI` set
// Regardless of whether C2 is enabled or not, the test should never fail.
public void testCrash() throws IOException {
assumeTrue("Requires C2, which is only enabled when CI env is set", getCIEnv() != null);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's a much easier way to detect if CI is enabled. Use assumeFalse(oal.util.Constants.IS_CLIENT_VM) (this was added for vector API detection: https://lucene.apache.org/core/9_9_1/core/org/apache/lucene/util/Constants.html#IS_CLIENT_VM)

int itrs = atLeast(100);
for (int i = 0; i < itrs; i++) {
try (Directory dir = newDirectory();
IndexWriter iw = new IndexWriter(dir, newIndexWriterConfig(null))) {
for (int d = 0; d < 20_000; d++) {
iw.addDocument(
List.of(new IntPoint("foo", 0), new SortedNumericDocValuesField("bar", 0)));
}
}
}
}

@SuppressForbidden(reason = "needed to check if C2 is enabled")
@SuppressWarnings("removal")
private static String getCIEnv() {
PrivilegedAction<String> pa = () -> System.getenv("CI");
return AccessController.doPrivileged(pa);
}
}