From ddf820a3a1cef4eb6136fa85e8e5b00c681240b0 Mon Sep 17 00:00:00 2001 From: William Brafford Date: Fri, 25 Oct 2019 13:27:43 -0400 Subject: [PATCH 1/2] Warn when MaxDirectMemorySize may be incorrect (Windows/JDK8 only issue) (#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. --- .../org/elasticsearch/tools/launchers/JvmErgonomics.java | 7 +++++++ .../elasticsearch/tools/launchers/JvmErgonomicsTests.java | 5 +++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/distribution/tools/launchers/src/main/java/org/elasticsearch/tools/launchers/JvmErgonomics.java b/distribution/tools/launchers/src/main/java/org/elasticsearch/tools/launchers/JvmErgonomics.java index d18ac681d751e..9abcebe130c3b 100644 --- a/distribution/tools/launchers/src/main/java/org/elasticsearch/tools/launchers/JvmErgonomics.java +++ b/distribution/tools/launchers/src/main/java/org/elasticsearch/tools/launchers/JvmErgonomics.java @@ -19,6 +19,8 @@ package org.elasticsearch.tools.launchers; +import org.elasticsearch.tools.java_version_checker.JavaVersion; + import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; @@ -66,6 +68,11 @@ static List choose(final List userDefinedJvmOptions) throws Inte } final long maxDirectMemorySize = extractMaxDirectMemorySize(finalJvmOptions); if (maxDirectMemorySize == 0) { + if (System.getProperty("os.name").startsWith("Windows") && JavaVersion.majorVersion(JavaVersion.CURRENT) == 8) { + Launchers.errPrintln("Warning: with JDK 8 on Windows, Elasticsearch may miscalculate MaxDirectMemorySize"); + Launchers.errPrintln(" due to a JDK issue (JDK-8074459)."); + Launchers.errPrintln(" Please use a newer version of Java or set MaxDirectMemorySize explicitly"); + } ergonomicChoices.add("-XX:MaxDirectMemorySize=" + heapSize / 2); } return ergonomicChoices; diff --git a/distribution/tools/launchers/src/test/java/org/elasticsearch/tools/launchers/JvmErgonomicsTests.java b/distribution/tools/launchers/src/test/java/org/elasticsearch/tools/launchers/JvmErgonomicsTests.java index ecda6e1f4d830..28318ed39648b 100644 --- a/distribution/tools/launchers/src/test/java/org/elasticsearch/tools/launchers/JvmErgonomicsTests.java +++ b/distribution/tools/launchers/src/test/java/org/elasticsearch/tools/launchers/JvmErgonomicsTests.java @@ -56,8 +56,8 @@ public void testExtractValidHeapSizeUsingMaxHeapSize() throws InterruptedExcepti } public void testExtractValidHeapSizeNoOptionPresent() throws InterruptedException, IOException { - // Muting on Windows, awaitsfix: https://github.com/elastic/elasticsearch/issues/47384 - assumeFalse(System.getProperty("os.name").startsWith("Windows")); + // Muted for jdk8/Windows, see: https://github.com/elastic/elasticsearch/issues/47384 + assumeFalse(System.getProperty("os.name").startsWith("Windows") && JavaVersion.majorVersion(JavaVersion.CURRENT) == 8); assertThat( JvmErgonomics.extractHeapSize(JvmErgonomics.finalJvmOptions(Collections.emptyList())), greaterThan(0L)); @@ -140,6 +140,7 @@ public void testPooledMemoryChoiceOnNotSmallHeap() throws InterruptedException, } public void testMaxDirectMemorySizeChoice() throws InterruptedException, IOException { + // Muted for jdk8/Windows, see: https://github.com/elastic/elasticsearch/issues/47384 assumeFalse(System.getProperty("os.name").startsWith("Windows") && JavaVersion.majorVersion(JavaVersion.CURRENT) == 8); final Map heapMaxDirectMemorySize = new HashMap<>(); heapMaxDirectMemorySize.put("64M", Long.toString((64L << 20) / 2)); From 90721b8564107f18b1fd2dd2f9a3fd7749baa7ec Mon Sep 17 00:00:00 2001 From: William Brafford Date: Fri, 25 Oct 2019 16:30:41 -0400 Subject: [PATCH 2/2] Warn for io.netty property on 7.5 for Windows/jdk8 --- .../org/elasticsearch/tools/launchers/JvmErgonomics.java | 5 +++++ .../elasticsearch/tools/launchers/JvmErgonomicsTests.java | 1 + 2 files changed, 6 insertions(+) diff --git a/distribution/tools/launchers/src/main/java/org/elasticsearch/tools/launchers/JvmErgonomics.java b/distribution/tools/launchers/src/main/java/org/elasticsearch/tools/launchers/JvmErgonomics.java index 9abcebe130c3b..d7246ebf5eed5 100644 --- a/distribution/tools/launchers/src/main/java/org/elasticsearch/tools/launchers/JvmErgonomics.java +++ b/distribution/tools/launchers/src/main/java/org/elasticsearch/tools/launchers/JvmErgonomics.java @@ -60,6 +60,11 @@ static List choose(final List userDefinedJvmOptions) throws Inte final long heapSize = extractHeapSize(finalJvmOptions); final Map systemProperties = extractSystemProperties(userDefinedJvmOptions); if (systemProperties.containsKey("io.netty.allocator.type") == false) { + if (System.getProperty("os.name").startsWith("Windows") && JavaVersion.majorVersion(JavaVersion.CURRENT) == 8) { + Launchers.errPrintln("Warning: with JDK 8 on Windows, Elasticsearch may set io.netty.allocator.type"); + Launchers.errPrintln(" incorrectly due to a JDK issue (JDK-8074459)."); + Launchers.errPrintln(" Please use a newer version of Java or set io.netty.allocator.type explicitly"); + } if (heapSize <= 1 << 30) { ergonomicChoices.add("-Dio.netty.allocator.type=unpooled"); } else { diff --git a/distribution/tools/launchers/src/test/java/org/elasticsearch/tools/launchers/JvmErgonomicsTests.java b/distribution/tools/launchers/src/test/java/org/elasticsearch/tools/launchers/JvmErgonomicsTests.java index 28318ed39648b..794d1675561db 100644 --- a/distribution/tools/launchers/src/test/java/org/elasticsearch/tools/launchers/JvmErgonomicsTests.java +++ b/distribution/tools/launchers/src/test/java/org/elasticsearch/tools/launchers/JvmErgonomicsTests.java @@ -132,6 +132,7 @@ public void testPooledMemoryChoiceOnSmallHeap() throws InterruptedException, IOE } public void testPooledMemoryChoiceOnNotSmallHeap() throws InterruptedException, IOException { + // Muted for jdk8/Windows, see: https://github.com/elastic/elasticsearch/issues/47384 assumeFalse(System.getProperty("os.name").startsWith("Windows") && JavaVersion.majorVersion(JavaVersion.CURRENT) == 8); final String largeHeap = randomFrom(Arrays.asList("1025M", "2048M", "2G", "8G")); assertThat(