/
SystemJvmOptions.java
90 lines (82 loc) · 3.78 KB
/
SystemJvmOptions.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
/*
* Licensed to Elasticsearch under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.elasticsearch.tools.launchers;
import org.elasticsearch.tools.java_version_checker.JavaVersion;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
final class SystemJvmOptions {
static List<String> systemJvmOptions() {
return Collections.unmodifiableList(
Arrays.asList(
/*
* Cache ttl in seconds for positive DNS lookups noting that this overrides the JDK security property
* networkaddress.cache.ttl; can be set to -1 to cache forever.
*/
"-Des.networkaddress.cache.ttl=60",
/*
* Cache ttl in seconds for negative DNS lookups noting that this overrides the JDK security property
* networkaddress.cache.negative ttl; set to -1 to cache forever.
*/
"-Des.networkaddress.cache.negative.ttl=10",
// pre-touch JVM emory pages during initialization
"-XX:+AlwaysPreTouch",
// explicitly set the stack size
"-Xss1m",
// set to headless, just in case,
"-Djava.awt.headless=true",
// ensure UTF-8 encoding by default (e.g., filenames)
"-Dfile.encoding=UTF-8",
// use our provided JNA always versus the system one
"-Djna.nosys=true",
/*
* Turn off a JDK optimization that throws away stack traces for common exceptions because stack traces are important for
* debugging.
*/
"-XX:-OmitStackTraceInFastThrow",
// flags to configure Netty
"-Dio.netty.noUnsafe=true",
"-Dio.netty.noKeySetOptimization=true",
"-Dio.netty.recycler.maxCapacityPerThread=0",
"-Dio.netty.allocator.numDirectArenas=0",
// log4j 2
"-Dlog4j.shutdownHookEnabled=false",
"-Dlog4j2.disable.jmx=true",
javaLocaleProviders()
)
);
}
private static String javaLocaleProviders() {
/**
* SPI setting is used to allow loading custom CalendarDataProvider
* in jdk8 it has to be loaded from jre/lib/ext,
* in jdk9+ it is already within ES project and on a classpath
*
* Due to internationalization enhancements in JDK 9 Elasticsearch need to set the provider to COMPAT otherwise time/date
* parsing will break in an incompatible way for some date patterns and locales.
* //TODO COMPAT will be deprecated in jdk14 https://bugs.openjdk.java.net/browse/JDK-8232906
* See also: documentation in <code>server/org.elasticsearch.common.time.IsoCalendarDataProvider</code>
*/
if (JavaVersion.majorVersion(JavaVersion.CURRENT) == 8) {
return "-Djava.locale.providers=SPI,JRE";
} else {
return "-Djava.locale.providers=SPI,COMPAT";
}
}
}