8185496: Improve performance of system properties initialization in initPhase1

8213424: VersionProps duplicate and skipped initialization

Reviewed-by: mchung, redestad, dholmes
This commit is contained in:
Roger Riggs 2018-11-09 13:28:16 -05:00
parent 1b20a6781f
commit 29e742273e
12 changed files with 311 additions and 184 deletions

View file

@ -802,6 +802,7 @@ public final class System {
if (props == null) {
props = new Properties();
initProperties(props);
VersionProps.init(props);
}
System.props = props;
}
@ -1973,6 +1974,7 @@ public final class System {
// be put into it directly.
props = new Properties(84);
initProperties(props); // initialized by the VM
VersionProps.init(props);
// There are certain system configurations that may be controlled by
// VM options such as the maximum amount of direct memory and
@ -1992,7 +1994,6 @@ public final class System {
lineSeparator = props.getProperty("line.separator");
StaticProperty.javaHome(); // Load StaticProperty to cache the property values
VersionProps.init();
FileInputStream fdIn = new FileInputStream(FileDescriptor.in);
FileOutputStream fdOut = new FileOutputStream(FileDescriptor.out);

View file

@ -29,6 +29,7 @@ import java.io.PrintStream;
import java.util.Arrays;
import java.util.List;
import java.util.Optional;
import java.util.Properties;
class VersionProps {
@ -69,17 +70,13 @@ class VersionProps {
(VENDOR_VERSION_STRING.length() > 0
? " " + VENDOR_VERSION_STRING : "");
static {
init();
}
public static void init() {
System.setProperty("java.version", java_version);
System.setProperty("java.version.date", java_version_date);
System.setProperty("java.runtime.version", java_runtime_version);
System.setProperty("java.runtime.name", java_runtime_name);
public static void init(Properties props) {
props.setProperty("java.version", java_version);
props.setProperty("java.version.date", java_version_date);
props.setProperty("java.runtime.version", java_runtime_version);
props.setProperty("java.runtime.name", java_runtime_name);
if (VENDOR_VERSION_STRING.length() > 0)
System.setProperty("java.vendor.version", VENDOR_VERSION_STRING);
props.setProperty("java.vendor.version", VENDOR_VERSION_STRING);
}
private static int parseVersionNumber(String version, int prevIndex, int index) {

View file

@ -199,17 +199,16 @@ public class VM {
// by the vm option -XX:MaxDirectMemorySize=<size>.
// The maximum amount of allocatable direct buffer memory (in bytes)
// from the system property sun.nio.MaxDirectMemorySize set by the VM.
// If not set or set to -1, the max memory will be used
// The system property will be removed.
String s = (String)props.remove("sun.nio.MaxDirectMemorySize");
if (s != null) {
if (s.equals("-1")) {
// -XX:MaxDirectMemorySize not given, take default
directMemory = Runtime.getRuntime().maxMemory();
} else {
long l = Long.parseLong(s);
if (l > -1)
directMemory = l;
}
if (s == null || s.isEmpty() || s.equals("-1")) {
// -XX:MaxDirectMemorySize not given, take default
directMemory = Runtime.getRuntime().maxMemory();
} else {
long l = Long.parseLong(s);
if (l > -1)
directMemory = l;
}
// Check if direct buffers should be page aligned

View file

@ -211,7 +211,6 @@ Java_java_lang_System_initProperties(JNIEnv *env, jclass cla, jobject props)
PUTPROP(props, "java.specification.vendor",
JAVA_SPECIFICATION_VENDOR);
PUTPROP(props, "java.version", VERSION_SHORT);
PUTPROP(props, "java.vendor", VENDOR);
PUTPROP(props, "java.vendor.url", VENDOR_URL);
PUTPROP(props, "java.vendor.url.bug", VENDOR_URL_BUG);
@ -255,8 +254,10 @@ Java_java_lang_System_initProperties(JNIEnv *env, jclass cla, jobject props)
/* unicode_encoding specifies the default endianness */
PUTPROP(props, "sun.io.unicode.encoding", sprops->unicode_encoding);
PUTPROP(props, "sun.cpu.isalist",
(sprops->cpu_isalist ? sprops->cpu_isalist : ""));
if (sprops->cpu_isalist != NULL) {
// leave undefined if none
PUTPROP(props, "sun.cpu.isalist", sprops->cpu_isalist);
}
PUTPROP(props, "sun.cpu.endian", sprops->cpu_endian);
@ -330,8 +331,10 @@ Java_java_lang_System_initProperties(JNIEnv *env, jclass cla, jobject props)
sprops->data_model);
/* patch level */
PUTPROP(props, "sun.os.patch.level", \
if (sprops->patch_level != NULL) {
PUTPROP(props, "sun.os.patch.level", \
sprops->patch_level);
}
/* Java2D properties */
/* Note: java.awt.graphicsenv is an implementation private property which
@ -354,9 +357,6 @@ Java_java_lang_System_initProperties(JNIEnv *env, jclass cla, jobject props)
PUTPROP_ForPlatformNString(props, "user.name", sprops->user_name);
PUTPROP_ForPlatformNString(props, "user.home", sprops->user_home);
PUTPROP(props, "user.timezone", sprops->timezone);
PUTPROP_ForPlatformNString(props, "user.dir", sprops->user_dir);
/* This is a sun. property as it is currently only set for Gnome and

View file

@ -56,23 +56,18 @@ typedef struct {
nchar *user_name;
nchar *user_home;
char *language;
char *format_language;
char *display_language;
char *script;
char *format_script;
char *display_script;
char *country;
char *format_country;
char *display_country;
char *variant;
char *format_variant;
char *display_variant;
char *encoding;
char *sun_jnu_encoding;
char *sun_stdout_encoding;
char *sun_stderr_encoding;
char *timezone;
char *printerJob;
char *graphics_env;