Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement MMapDirectory with Java 21 Project Panama Preview API #12294

Merged
merged 11 commits into from
Jun 12, 2023
2 changes: 1 addition & 1 deletion buildSrc/scriptDepVersions.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
ext {
scriptDepVersions = [
"apache-rat": "0.14",
"asm": "9.4",
"asm": "9.5",
"commons-codec": "1.13",
"ecj": "3.30.0",
"flexmark": "0.61.24",
Expand Down
2 changes: 1 addition & 1 deletion gradle/generation/extract-jdk-apis.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ configure(rootProject) {
configure(project(":lucene:core")) {
ext {
apijars = file('src/generated/jdk');
mrjarJavaVersions = [ 19, 20 ]
mrjarJavaVersions = [ 19, 20, 21 ]
}

configurations {
Expand Down
3 changes: 2 additions & 1 deletion gradle/generation/extract-jdk-apis/ExtractJdkApis.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ public final class ExtractJdkApis {

static final Map<Integer,List<String>> CLASSFILE_PATTERNS = Map.of(
19, List.of(PATTERN_PANAMA_FOREIGN),
20, List.of(PATTERN_PANAMA_FOREIGN, PATTERN_VECTOR_VM_INTERNALS, PATTERN_VECTOR_INCUBATOR)
20, List.of(PATTERN_PANAMA_FOREIGN, PATTERN_VECTOR_VM_INTERNALS, PATTERN_VECTOR_INCUBATOR),
21, List.of(PATTERN_PANAMA_FOREIGN)
);

public static void main(String... args) throws IOException {
Expand Down
2 changes: 1 addition & 1 deletion gradle/template.gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -102,5 +102,5 @@ tests.jvms=@TEST_JVMS@
org.gradle.java.installations.auto-download=true

# Set these to enable automatic JVM location discovery.
org.gradle.java.installations.fromEnv=JAVA17_HOME,JAVA19_HOME,JAVA20_HOME,JAVA21_HOME,RUNTIME_JAVA_HOME
org.gradle.java.installations.fromEnv=JAVA17_HOME,JAVA19_HOME,JAVA20_HOME,JAVA21_HOME,JAVA22_HOME,RUNTIME_JAVA_HOME
#org.gradle.java.installations.paths=(custom paths)
Binary file added lucene/core/src/generated/jdk/jdk21.apijar
Binary file not shown.
14 changes: 7 additions & 7 deletions lucene/core/src/java/org/apache/lucene/store/MMapDirectory.java
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,9 @@
* <li>{@code permission java.lang.RuntimePermission "accessClassInPackage.sun.misc";}
* </ul>
*
* <p>On exactly <b>Java 19</b> and <b>Java 20</b> this class will use the modern {@code
* MemorySegment} API which allows to safely unmap (if you discover any problems with this preview
* API, you can disable it by using system property {@link #ENABLE_MEMORY_SEGMENTS_SYSPROP}).
* <p>On exactly <b>Java 19 / 20 / 21</b> this class will use the modern {@code MemorySegment} API
* which allows to safely unmap (if you discover any problems with this preview API, you can disable
* it by using system property {@link #ENABLE_MEMORY_SEGMENTS_SYSPROP}).
*
* <p><b>NOTE:</b> Accessing this class either directly or indirectly from a thread while it's
* interrupted can close the underlying channel immediately if at the same time the thread is
Expand Down Expand Up @@ -123,7 +123,7 @@ public class MMapDirectory extends FSDirectory {
* Default max chunk size:
*
* <ul>
* <li>16 GiBytes for 64 bit <b>Java 19</b> and <b>Java 20</b> JVMs
* <li>16 GiBytes for 64 bit <b>Java 19 / 20 / 21</b> JVMs
* <li>1 GiBytes for other 64 bit JVMs
* <li>256 MiBytes for 32 bit JVMs
* </ul>
Expand Down Expand Up @@ -346,7 +346,7 @@ private static MMapIndexInputProvider lookupProvider() {
}
final var lookup = MethodHandles.lookup();
final int runtimeVersion = Runtime.version().feature();
if (runtimeVersion == 19 || runtimeVersion == 20) {
if (runtimeVersion >= 19 && runtimeVersion <= 21) {
try {
final var cls = lookup.findClass("org.apache.lucene.store.MemorySegmentIndexInputProvider");
// we use method handles, so we do not need to deal with setAccessible as we have private
Expand All @@ -366,9 +366,9 @@ private static MMapIndexInputProvider lookupProvider() {
throw new LinkageError(
"MemorySegmentIndexInputProvider is missing in Lucene JAR file", cnfe);
}
} else if (runtimeVersion >= 21) {
} else if (runtimeVersion >= 22) {
LOG.warning(
"You are running with Java 21 or later. To make full use of MMapDirectory, please update Apache Lucene.");
"You are running with Java 22 or later. To make full use of MMapDirectory, please update Apache Lucene.");
}
return new MappedByteBufferIndexInputProvider();
}
Expand Down
Loading