|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
*/ |
|
package jdk.internal.util; |
|
|
|
|
|
import java.lang.annotation.Native; |
|
import java.util.HashMap; |
|
import java.util.Map; |
|
|
|
|
|
|
|
|
|
|
|
|
|
*/ |
|
public final class SystemProps { |
|
|
|
|
|
private SystemProps() {} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
*/ |
|
public static Map<String, String> initProperties() { |
|
|
|
|
|
Raw raw = new Raw(); |
|
HashMap<String, String> props = raw.cmdProperties(); |
|
|
|
String javaHome = props.get("java.home"); |
|
assert javaHome != null : "java.home not set"; |
|
|
|
putIfAbsent(props, "user.home", raw.propDefault(Raw._user_home_NDX)); |
|
putIfAbsent(props, "user.dir", raw.propDefault(Raw._user_dir_NDX)); |
|
putIfAbsent(props, "user.name", raw.propDefault(Raw._user_name_NDX)); |
|
|
|
|
|
put(props, "sun.jnu.encoding", raw.propDefault(Raw._sun_jnu_encoding_NDX)); |
|
var nativeEncoding = ((raw.propDefault(Raw._file_encoding_NDX) == null) |
|
? raw.propDefault(Raw._sun_jnu_encoding_NDX) |
|
: raw.propDefault(Raw._file_encoding_NDX)); |
|
put(props, "native.encoding", nativeEncoding); |
|
|
|
|
|
putIfAbsent(props, "file.encoding", nativeEncoding); |
|
|
|
// Use platform values if not overridden by a commandline -Dkey=value |
|
|
|
putIfAbsent(props, "os.name", raw.propDefault(Raw._os_name_NDX)); |
|
putIfAbsent(props, "os.arch", raw.propDefault(Raw._os_arch_NDX)); |
|
putIfAbsent(props, "os.version", raw.propDefault(Raw._os_version_NDX)); |
|
putIfAbsent(props, "line.separator", raw.propDefault(Raw._line_separator_NDX)); |
|
putIfAbsent(props, "file.separator", raw.propDefault(Raw._file_separator_NDX)); |
|
putIfAbsent(props, "path.separator", raw.propDefault(Raw._path_separator_NDX)); |
|
putIfAbsent(props, "java.io.tmpdir", raw.propDefault(Raw._java_io_tmpdir_NDX)); |
|
putIfAbsent(props, "http.proxyHost", raw.propDefault(Raw._http_proxyHost_NDX)); |
|
putIfAbsent(props, "http.proxyPort", raw.propDefault(Raw._http_proxyPort_NDX)); |
|
putIfAbsent(props, "https.proxyHost", raw.propDefault(Raw._https_proxyHost_NDX)); |
|
putIfAbsent(props, "https.proxyPort", raw.propDefault(Raw._https_proxyPort_NDX)); |
|
putIfAbsent(props, "ftp.proxyHost", raw.propDefault(Raw._ftp_proxyHost_NDX)); |
|
putIfAbsent(props, "ftp.proxyPort", raw.propDefault(Raw._ftp_proxyPort_NDX)); |
|
putIfAbsent(props, "socksProxyHost", raw.propDefault(Raw._socksProxyHost_NDX)); |
|
putIfAbsent(props, "socksProxyPort", raw.propDefault(Raw._socksProxyPort_NDX)); |
|
putIfAbsent(props, "http.nonProxyHosts", raw.propDefault(Raw._http_nonProxyHosts_NDX)); |
|
putIfAbsent(props, "ftp.nonProxyHosts", raw.propDefault(Raw._ftp_nonProxyHosts_NDX)); |
|
putIfAbsent(props, "socksNonProxyHosts", raw.propDefault(Raw._socksNonProxyHosts_NDX)); |
|
putIfAbsent(props, "sun.arch.abi", raw.propDefault(Raw._sun_arch_abi_NDX)); |
|
putIfAbsent(props, "sun.arch.data.model", raw.propDefault(Raw._sun_arch_data_model_NDX)); |
|
putIfAbsent(props, "sun.os.patch.level", raw.propDefault(Raw._sun_os_patch_level_NDX)); |
|
putIfAbsent(props, "sun.stdout.encoding", raw.propDefault(Raw._sun_stdout_encoding_NDX)); |
|
putIfAbsent(props, "sun.stderr.encoding", raw.propDefault(Raw._sun_stderr_encoding_NDX)); |
|
putIfAbsent(props, "sun.io.unicode.encoding", raw.propDefault(Raw._sun_io_unicode_encoding_NDX)); |
|
putIfAbsent(props, "sun.cpu.isalist", raw.propDefault(Raw._sun_cpu_isalist_NDX)); |
|
putIfAbsent(props, "sun.cpu.endian", raw.propDefault(Raw._sun_cpu_endian_NDX)); |
|
|
|
|
|
fillI18nProps(props,"user.language", raw.propDefault(Raw._display_language_NDX), |
|
raw.propDefault(Raw._format_language_NDX)); |
|
fillI18nProps(props,"user.script", raw.propDefault(Raw._display_script_NDX), |
|
raw.propDefault(Raw._format_script_NDX)); |
|
fillI18nProps(props,"user.country", raw.propDefault(Raw._display_country_NDX), |
|
raw.propDefault(Raw._format_country_NDX)); |
|
fillI18nProps(props,"user.variant", raw.propDefault(Raw._display_variant_NDX), |
|
raw.propDefault(Raw._format_variant_NDX)); |
|
|
|
return props; |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
*/ |
|
private static void put(HashMap<String, String> props, String key, String value) { |
|
if (value != null) { |
|
props.put(key, value); |
|
} |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
*/ |
|
private static void putIfAbsent(HashMap<String, String> props, String key, String value) { |
|
if (value != null) { |
|
props.putIfAbsent(key, value); |
|
} |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
*/ |
|
private static void fillI18nProps(HashMap<String, String> cmdProps, |
|
String base, |
|
String display, |
|
String format) { |
|
|
|
String baseValue = cmdProps.get(base); |
|
if (baseValue != null) { |
|
return; |
|
} |
|
|
|
|
|
if (display != null) { |
|
cmdProps.put(base, display); |
|
baseValue = display; |
|
} |
|
|
|
|
|
String disp = base.concat(".display"); |
|
String dispValue = cmdProps.get(disp); |
|
if (dispValue == null && display != null && !display.equals(baseValue)) { |
|
|
|
cmdProps.put(disp, display); |
|
} |
|
|
|
|
|
String fmt = base.concat(".format"); |
|
String fmtValue = cmdProps.get(fmt); |
|
if (fmtValue == null && format != null && !format.equals(baseValue)) { |
|
|
|
cmdProps.put(fmt, format); |
|
} |
|
} |
|
|
|
|
|
|
|
*/ |
|
public static class Raw { |
|
// Array indices written by native vmProperties() |
|
|
|
@Native private static final int _display_country_NDX = 0; |
|
@Native private static final int _display_language_NDX = 1 + _display_country_NDX; |
|
@Native private static final int _display_script_NDX = 1 + _display_language_NDX; |
|
@Native private static final int _display_variant_NDX = 1 + _display_script_NDX; |
|
@Native private static final int _file_encoding_NDX = 1 + _display_variant_NDX; |
|
@Native private static final int _file_separator_NDX = 1 + _file_encoding_NDX; |
|
@Native private static final int _format_country_NDX = 1 + _file_separator_NDX; |
|
@Native private static final int _format_language_NDX = 1 + _format_country_NDX; |
|
@Native private static final int _format_script_NDX = 1 + _format_language_NDX; |
|
@Native private static final int _format_variant_NDX = 1 + _format_script_NDX; |
|
@Native private static final int _ftp_nonProxyHosts_NDX = 1 + _format_variant_NDX; |
|
@Native private static final int _ftp_proxyHost_NDX = 1 + _ftp_nonProxyHosts_NDX; |
|
@Native private static final int _ftp_proxyPort_NDX = 1 + _ftp_proxyHost_NDX; |
|
@Native private static final int _http_nonProxyHosts_NDX = 1 + _ftp_proxyPort_NDX; |
|
@Native private static final int _http_proxyHost_NDX = 1 + _http_nonProxyHosts_NDX; |
|
@Native private static final int _http_proxyPort_NDX = 1 + _http_proxyHost_NDX; |
|
@Native private static final int _https_proxyHost_NDX = 1 + _http_proxyPort_NDX; |
|
@Native private static final int _https_proxyPort_NDX = 1 + _https_proxyHost_NDX; |
|
@Native private static final int _java_io_tmpdir_NDX = 1 + _https_proxyPort_NDX; |
|
@Native private static final int _line_separator_NDX = 1 + _java_io_tmpdir_NDX; |
|
@Native private static final int _os_arch_NDX = 1 + _line_separator_NDX; |
|
@Native private static final int _os_name_NDX = 1 + _os_arch_NDX; |
|
@Native private static final int _os_version_NDX = 1 + _os_name_NDX; |
|
@Native private static final int _path_separator_NDX = 1 + _os_version_NDX; |
|
@Native private static final int _socksNonProxyHosts_NDX = 1 + _path_separator_NDX; |
|
@Native private static final int _socksProxyHost_NDX = 1 + _socksNonProxyHosts_NDX; |
|
@Native private static final int _socksProxyPort_NDX = 1 + _socksProxyHost_NDX; |
|
@Native private static final int _sun_arch_abi_NDX = 1 + _socksProxyPort_NDX; |
|
@Native private static final int _sun_arch_data_model_NDX = 1 + _sun_arch_abi_NDX; |
|
@Native private static final int _sun_cpu_endian_NDX = 1 + _sun_arch_data_model_NDX; |
|
@Native private static final int _sun_cpu_isalist_NDX = 1 + _sun_cpu_endian_NDX; |
|
@Native private static final int _sun_io_unicode_encoding_NDX = 1 + _sun_cpu_isalist_NDX; |
|
@Native private static final int _sun_jnu_encoding_NDX = 1 + _sun_io_unicode_encoding_NDX; |
|
@Native private static final int _sun_os_patch_level_NDX = 1 + _sun_jnu_encoding_NDX; |
|
@Native private static final int _sun_stderr_encoding_NDX = 1 + _sun_os_patch_level_NDX; |
|
@Native private static final int _sun_stdout_encoding_NDX = 1 + _sun_stderr_encoding_NDX; |
|
@Native private static final int _user_dir_NDX = 1 + _sun_stdout_encoding_NDX; |
|
@Native private static final int _user_home_NDX = 1 + _user_dir_NDX; |
|
@Native private static final int _user_name_NDX = 1 + _user_home_NDX; |
|
@Native private static final int FIXED_LENGTH = 1 + _user_name_NDX; |
|
|
|
// Array of Strings returned from the VM and Command line properties |
|
|
|
private final String[] platformProps; |
|
|
|
private Raw() { |
|
platformProps = platformProperties(); |
|
} |
|
|
|
|
|
|
|
|
|
|
|
*/ |
|
String propDefault(int index) { |
|
return platformProps[index]; |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
*/ |
|
private HashMap<String, String> cmdProperties() { |
|
String[] vmProps = vmProperties(); |
|
// While optimal initialCapacity here would be the exact number of properties |
|
// divided by LOAD_FACTOR, a large portion of the properties in Raw are |
|
|
|
var cmdProps = new HashMap<String, String>((vmProps.length / 2) + Raw.FIXED_LENGTH); |
|
for (int i = 0; i < vmProps.length;) { |
|
String k = vmProps[i++]; |
|
if (k != null) { |
|
String v = vmProps[i++]; |
|
cmdProps.put(k, v != null ? v : ""); |
|
} else { |
|
|
|
break; |
|
} |
|
} |
|
return cmdProps; |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
*/ |
|
private static native String[] vmProperties(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
*/ |
|
private static native String[] platformProperties(); |
|
} |
|
} |