Skip to content

Commit 3b9c728

Browse files
authored
MR-JAR rewrite of MMapDirectory with JDK-19 preview Panama APIs (>= JDK-19-ea+23) (#912)
This uses Gradle's auto-provisioning to compile Java 19 classes and build a multi-release JAR from them. Please make sure to regenerate gradle.properties (delete it) or change "org.gradle.java.installations.auto-download" to "true"
1 parent 432296d commit 3b9c728

14 files changed

Lines changed: 1217 additions & 214 deletions

File tree

gradle/generation/local-settings.gradle

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -98,12 +98,12 @@ org.gradle.workers.max=${maxWorkers}
9898
# Maximum number of test JVMs forked per test task.
9999
tests.jvms=${testsJvms}
100100
101-
# Disable auto JVM provisioning (we don't use toolchains yet but want no surprises).
102-
org.gradle.java.installations.auto-download=false
101+
# Enable auto JVM provisioning.
102+
org.gradle.java.installations.auto-download=true
103103
104104
# Set these to enable automatic JVM location discovery.
105-
org.gradle.java.installations.fromEnv=JDK11,JDK12,JDK13,JDK14,JDK15,JDK16,JDK17
106-
org.gradle.java.installations.paths=(custom paths)
105+
org.gradle.java.installations.fromEnv=JAVA17_HOME,JAVA19_HOME
106+
#org.gradle.java.installations.paths=(custom paths)
107107
108108
""", "UTF-8")
109109

gradle/java/javac.gradle

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,3 +79,48 @@ allprojects {
7979
}
8080
}
8181
}
82+
83+
configure(project(":lucene:core")) {
84+
plugins.withType(JavaPlugin) {
85+
sourceSets {
86+
main19 {
87+
java {
88+
srcDirs = ['src/java19']
89+
}
90+
}
91+
}
92+
93+
configurations {
94+
// Inherit any dependencies from the main source set.
95+
main19Implementation.extendsFrom implementation
96+
}
97+
98+
dependencies {
99+
// We need the main classes to compile our Java 19 pieces.
100+
main19Implementation sourceSets.main.output
101+
}
102+
103+
tasks.named('compileMain19Java').configure {
104+
javaCompiler = javaToolchains.compilerFor {
105+
languageVersion = JavaLanguageVersion.of(19)
106+
}
107+
108+
// undo alternative JDK support:
109+
options.forkOptions.javaHome = null
110+
111+
sourceCompatibility = 19
112+
targetCompatibility = 19
113+
options.compilerArgs += ["--release", 19 as String, "--enable-preview"]
114+
}
115+
116+
tasks.named('jar').configure {
117+
into('META-INF/versions/19') {
118+
from sourceSets.main19.output
119+
}
120+
121+
manifest.attributes(
122+
'Multi-Release': 'true'
123+
)
124+
}
125+
}
126+
}

gradle/testing/defaults-tests.gradle

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,10 @@ allprojects {
124124
// (if the runner JVM does not support them, it will fail tests):
125125
jvmArgs '--add-modules', 'jdk.unsupported,jdk.management'
126126

127+
if (rootProject.runtimeJavaVersion == JavaVersion.VERSION_19) {
128+
jvmArgs '--enable-preview'
129+
}
130+
127131
systemProperty 'java.util.logging.config.file', file("${resources}/logging.properties")
128132
systemProperty 'java.awt.headless', 'true'
129133
systemProperty 'jdk.map.althashing.threshold', '0'

gradle/validation/ecj-lint.gradle

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,9 @@ allprojects {
3434
// Create a [sourceSetName]EcjLint task for each source set
3535
// with a non-empty java.srcDirs. These tasks are then
3636
// attached to project's "ecjLint" task.
37-
def lintTasks = sourceSets.collect { sourceSet ->
37+
38+
// TODO: Better way to disable on our MR-JAR
39+
def lintTasks = sourceSets.findAll { it.name != 'main19' }.collect { sourceSet ->
3840
def srcDirs = sourceSet.java.sourceDirectories
3941
.filter { dir -> dir.exists() }
4042

gradle/validation/error-prone.gradle

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,12 @@ allprojects { prj ->
5858
}
5959

6060
tasks.withType(JavaCompile) { task ->
61+
// TODO: Better way to disable on our MR-JAR
62+
if (task.name == 'compileMain19Java') {
63+
options.errorprone.enabled = false
64+
return
65+
}
66+
6167
task.dependsOn ":checkJdkInternalsExportedToGradle"
6268

6369
options.errorprone.disableWarningsInGeneratedCode = true

gradle/validation/forbidden-apis.gradle

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,11 @@ allprojects { prj ->
115115
inputs.dir(file(resources))
116116
}
117117

118+
// TODO: Remove this when forbiddenapis supports Java 19 class files
119+
tasks.matching { it.name == "forbiddenApisMain19" }.all {
120+
enabled = false
121+
}
122+
118123
// We rely on resolved configurations to compute the relevant set of rule
119124
// files for forbiddenApis. Since we don't want to resolve these configurations until
120125
// the task is executed, we can't really use them as task inputs properly. This is a

lucene/CHANGES.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,15 @@ New Features
141141
SortField#getOptimizeSortWithIndexedData were introduce to provide
142142
an option to disable sort optimization for various sort fields. (Mayya Sharipova)
143143

144+
* GITHUB#912: Support for Java 19 foreign memory support was added. Applications started
145+
with command line parameter "java --enable-preview" will automatically use the new
146+
foreign memory API of Java 19 to access indexes on disk with MMapDirectory. This is
147+
an opt-in feature and requires explicit Java command line flag! When enabled, Lucene logs
148+
a notice using java.util.logging. Please test thoroughly and report bugs/slowness to Lucene's
149+
mailing list. When the new API is used, MMapDirectory will mmap Lucene indexes in chunks of
150+
16 GiB (instead of 1 GiB) and indexes closed while queries are running can no longer crash
151+
the JVM. (Uwe Schindler)
152+
144153
Improvements
145154
---------------------
146155
* LUCENE-10592: Build HNSW Graph on indexing. (Mayya Sharipova, Adrien Grand, Julie Tibshirani)

0 commit comments

Comments
 (0)