mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-27 06:45:07 +02:00
8215159
: Improve initial setup of system Properties
Reviewed-by: mchung, rriggs, plevart, briangoetz, robilad
This commit is contained in:
parent
ade1d52ab6
commit
d1ef9b19d7
4 changed files with 84 additions and 63 deletions
|
@ -801,8 +801,9 @@ public final class System {
|
|||
}
|
||||
|
||||
if (props == null) {
|
||||
props = SystemProps.initProperties();
|
||||
VersionProps.init(props);
|
||||
Map<String, String> tempProps = SystemProps.initProperties();
|
||||
VersionProps.init(tempProps);
|
||||
props = createProperties(tempProps);
|
||||
}
|
||||
System.props = props;
|
||||
}
|
||||
|
@ -1959,18 +1960,42 @@ public final class System {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the Properties object from a map - masking out system properties
|
||||
* that are not intended for public access.
|
||||
*/
|
||||
private static Properties createProperties(Map<String, String> initialProps) {
|
||||
Properties properties = new Properties(initialProps.size());
|
||||
for (var entry : initialProps.entrySet()) {
|
||||
String prop = entry.getKey();
|
||||
switch (prop) {
|
||||
// Do not add private system properties to the Properties
|
||||
case "sun.nio.MaxDirectMemorySize":
|
||||
case "sun.nio.PageAlignDirectMemory":
|
||||
// used by java.lang.Integer.IntegerCache
|
||||
case "java.lang.Integer.IntegerCache.high":
|
||||
// used by sun.launcher.LauncherHelper
|
||||
case "sun.java.launcher.diag":
|
||||
// used by jdk.internal.loader.ClassLoaders
|
||||
case "jdk.boot.class.path.append":
|
||||
break;
|
||||
default:
|
||||
properties.put(prop, entry.getValue());
|
||||
}
|
||||
}
|
||||
return properties;
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize the system class. Called after thread initialization.
|
||||
*/
|
||||
private static void initPhase1() {
|
||||
|
||||
// VM might invoke JNU_NewStringPlatform() to set those encoding
|
||||
// sensitive properties (user.home, user.name, boot.class.path, etc.)
|
||||
// during "props" initialization.
|
||||
// The charset is initialized in System.c and does not depend on the Properties.
|
||||
props = SystemProps.initProperties();
|
||||
VersionProps.init(props);
|
||||
StaticProperty.javaHome(); // Load StaticProperty to cache the property values
|
||||
Map<String, String> tempProps = SystemProps.initProperties();
|
||||
VersionProps.init(tempProps);
|
||||
|
||||
// There are certain system configurations that may be controlled by
|
||||
// VM options such as the maximum amount of direct memory and
|
||||
|
@ -1978,15 +2003,14 @@ public final class System {
|
|||
// of autoboxing. Typically, the library will obtain these values
|
||||
// from the properties set by the VM. If the properties are for
|
||||
// internal implementation use only, these properties should be
|
||||
// removed from the system properties.
|
||||
//
|
||||
// See java.lang.Integer.IntegerCache and the
|
||||
// VM.saveAndRemoveProperties method for example.
|
||||
// masked from the system properties.
|
||||
//
|
||||
// Save a private copy of the system properties object that
|
||||
// can only be accessed by the internal implementation. Remove
|
||||
// certain system properties that are not intended for public access.
|
||||
VM.saveAndRemoveProperties(props);
|
||||
// can only be accessed by the internal implementation.
|
||||
VM.saveProperties(tempProps);
|
||||
props = createProperties(tempProps);
|
||||
|
||||
StaticProperty.javaHome(); // Load StaticProperty to cache the property values
|
||||
|
||||
lineSeparator = props.getProperty("line.separator");
|
||||
|
||||
|
|
|
@ -28,8 +28,8 @@ package java.lang;
|
|||
import java.io.PrintStream;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.Properties;
|
||||
|
||||
class VersionProps {
|
||||
|
||||
|
@ -88,25 +88,25 @@ class VersionProps {
|
|||
/**
|
||||
* Initialize system properties using build provided values.
|
||||
*
|
||||
* @param props Properties instance in which to insert the properties
|
||||
* @param props Map instance in which to insert the properties
|
||||
*/
|
||||
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);
|
||||
public static void init(Map<String, String> props) {
|
||||
props.put("java.version", java_version);
|
||||
props.put("java.version.date", java_version_date);
|
||||
props.put("java.runtime.version", java_runtime_version);
|
||||
props.put("java.runtime.name", java_runtime_name);
|
||||
if (VENDOR_VERSION_STRING.length() > 0)
|
||||
props.setProperty("java.vendor.version", VENDOR_VERSION_STRING);
|
||||
props.put("java.vendor.version", VENDOR_VERSION_STRING);
|
||||
|
||||
props.setProperty("java.class.version", CLASSFILE_MAJOR_MINOR);
|
||||
props.put("java.class.version", CLASSFILE_MAJOR_MINOR);
|
||||
|
||||
props.setProperty("java.specification.version", VERSION_SPECIFICATION);
|
||||
props.setProperty("java.specification.name", "Java Platform API Specification");
|
||||
props.setProperty("java.specification.vendor", "Oracle Corporation");
|
||||
props.put("java.specification.version", VERSION_SPECIFICATION);
|
||||
props.put("java.specification.name", "Java Platform API Specification");
|
||||
props.put("java.specification.vendor", "Oracle Corporation");
|
||||
|
||||
props.setProperty("java.vendor", VENDOR);
|
||||
props.setProperty("java.vendor.url", VENDOR_URL);
|
||||
props.setProperty("java.vendor.url.bug", VENDOR_URL_BUG);
|
||||
props.put("java.vendor", VENDOR);
|
||||
props.put("java.vendor.url", VENDOR_URL);
|
||||
props.put("java.vendor.url.bug", VENDOR_URL_BUG);
|
||||
}
|
||||
|
||||
private static int parseVersionNumber(String version, int prevIndex, int index) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue