Skip to content

Commit ddf820a

Browse files
Warn when MaxDirectMemorySize may be incorrect (Windows/JDK8 only issue) (elastic#48365)
Our JVM ergonomics extract max heap size from JDK PrintFlagsFinal output. On JDK 8, there is a system-dependent bug where memory sizes are cast to 32-bit integers. On affected systems (namely, Windows), when 1/4 of physical memory is more than the maximum integer value, the output of PrintFlagsFinal will be inaccurate. In the pathological case, where the max heap size would be a multiple of 4g, the test will fail. The practical effect of this bug, beyond test failures, is that we may set MaxDirectMemorySize to an incorrect value on Windows. This commit adds a warning about this situation during startup.
1 parent 7da778a commit ddf820a

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

distribution/tools/launchers/src/main/java/org/elasticsearch/tools/launchers/JvmErgonomics.java

+7
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919

2020
package org.elasticsearch.tools.launchers;
2121

22+
import org.elasticsearch.tools.java_version_checker.JavaVersion;
23+
2224
import java.io.BufferedReader;
2325
import java.io.IOException;
2426
import java.io.InputStream;
@@ -66,6 +68,11 @@ static List<String> choose(final List<String> userDefinedJvmOptions) throws Inte
6668
}
6769
final long maxDirectMemorySize = extractMaxDirectMemorySize(finalJvmOptions);
6870
if (maxDirectMemorySize == 0) {
71+
if (System.getProperty("os.name").startsWith("Windows") && JavaVersion.majorVersion(JavaVersion.CURRENT) == 8) {
72+
Launchers.errPrintln("Warning: with JDK 8 on Windows, Elasticsearch may miscalculate MaxDirectMemorySize");
73+
Launchers.errPrintln(" due to a JDK issue (JDK-8074459).");
74+
Launchers.errPrintln(" Please use a newer version of Java or set MaxDirectMemorySize explicitly");
75+
}
6976
ergonomicChoices.add("-XX:MaxDirectMemorySize=" + heapSize / 2);
7077
}
7178
return ergonomicChoices;

distribution/tools/launchers/src/test/java/org/elasticsearch/tools/launchers/JvmErgonomicsTests.java

+3-2
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,8 @@ public void testExtractValidHeapSizeUsingMaxHeapSize() throws InterruptedExcepti
5656
}
5757

5858
public void testExtractValidHeapSizeNoOptionPresent() throws InterruptedException, IOException {
59-
// Muting on Windows, awaitsfix: https://github.com/elastic/elasticsearch/issues/47384
60-
assumeFalse(System.getProperty("os.name").startsWith("Windows"));
59+
// Muted for jdk8/Windows, see: https://github.com/elastic/elasticsearch/issues/47384
60+
assumeFalse(System.getProperty("os.name").startsWith("Windows") && JavaVersion.majorVersion(JavaVersion.CURRENT) == 8);
6161
assertThat(
6262
JvmErgonomics.extractHeapSize(JvmErgonomics.finalJvmOptions(Collections.emptyList())),
6363
greaterThan(0L));
@@ -140,6 +140,7 @@ public void testPooledMemoryChoiceOnNotSmallHeap() throws InterruptedException,
140140
}
141141

142142
public void testMaxDirectMemorySizeChoice() throws InterruptedException, IOException {
143+
// Muted for jdk8/Windows, see: https://github.com/elastic/elasticsearch/issues/47384
143144
assumeFalse(System.getProperty("os.name").startsWith("Windows") && JavaVersion.majorVersion(JavaVersion.CURRENT) == 8);
144145
final Map<String, String> heapMaxDirectMemorySize = new HashMap<>();
145146
heapMaxDirectMemorySize.put("64M", Long.toString((64L << 20) / 2));

0 commit comments

Comments
 (0)