40 |
package java.lang; |
package java.lang; |
41 |
|
|
42 |
import gnu.classpath.Configuration; |
import gnu.classpath.Configuration; |
43 |
|
import gnu.classpath.SystemProperties; |
44 |
|
|
45 |
import java.io.InputStream; |
import java.io.InputStream; |
46 |
import java.io.PrintStream; |
import java.io.PrintStream; |
62 |
// in vm/reference/java/lang/Runtime for implications of this fact. |
// in vm/reference/java/lang/Runtime for implications of this fact. |
63 |
|
|
64 |
/** |
/** |
|
* The System Class Loader (a.k.a. Application Class Loader). The one |
|
|
* returned by ClassLoader.getSystemClassLoader. It lives here to prevent |
|
|
* a circular initialization dependency between System and ClassLoader. |
|
|
* |
|
|
* We can't make it a blank final, since initSystemClassLoader is a |
|
|
* sub-function. |
|
|
*/ |
|
|
static ClassLoader systemClassLoader; |
|
|
|
|
|
/** |
|
|
* Stores the current system properties. This can be modified by |
|
|
* {@link #setProperties(Properties)}, but will never be null, because |
|
|
* setProperties(null) sucks in the default properties. |
|
|
*/ |
|
|
static Properties properties; |
|
|
|
|
|
/** |
|
65 |
* The standard InputStream. This is assigned at startup and starts its |
* The standard InputStream. This is assigned at startup and starts its |
66 |
* life perfectly valid. Although it is marked final, you can change it |
* life perfectly valid. Although it is marked final, you can change it |
67 |
* using {@link #setIn(InputStream)} through some hefty VM magic. |
* using {@link #setIn(InputStream)} through some hefty VM magic. |
71 |
* other processes or files. That should all be transparent to you, |
* other processes or files. That should all be transparent to you, |
72 |
* however. |
* however. |
73 |
*/ |
*/ |
74 |
public static final InputStream in; |
public static final InputStream in = VMSystem.makeStandardInputStream(); |
75 |
|
|
76 |
/** |
/** |
77 |
* The standard output PrintStream. This is assigned at startup and |
* The standard output PrintStream. This is assigned at startup and |
83 |
* output to other processes or files. That should all be transparent to |
* output to other processes or files. That should all be transparent to |
84 |
* you, however. |
* you, however. |
85 |
*/ |
*/ |
86 |
public static final PrintStream out; |
public static final PrintStream out = VMSystem.makeStandardOutputStream(); |
87 |
|
|
88 |
/** |
/** |
89 |
* The standard output PrintStream. This is assigned at startup and |
* The standard output PrintStream. This is assigned at startup and |
95 |
* output to other processes or files. That should all be transparent to |
* output to other processes or files. That should all be transparent to |
96 |
* you, however. |
* you, however. |
97 |
*/ |
*/ |
98 |
public static final PrintStream err; |
public static final PrintStream err = VMSystem.makeStandardErrorStream(); |
|
|
|
|
/** |
|
|
* Add to the default properties. The field is stored in Runtime, because |
|
|
* of the bootstrap sequence; but this adds several useful properties to |
|
|
* the defaults. Once the default is stabilized, it should not be modified; |
|
|
* instead it is passed as a parent properties for fast setup of the |
|
|
* defaults when calling <code>setProperties(null)</code>. |
|
|
*/ |
|
|
static |
|
|
{ |
|
|
if (! Configuration.JAVA_LANG_SYSTEM_EXPLICIT_INITIALIZATION) { |
|
|
initLoadLibrary(); |
|
|
initProperties(); |
|
|
} |
|
|
// We *have to* explicitly initialize the streams here, since they're a |
|
|
// blank final field. |
|
|
in = VMSystem.makeStandardInputStream(); |
|
|
out = VMSystem.makeStandardOutputStream(); |
|
|
err = VMSystem.makeStandardErrorStream(); |
|
|
|
|
|
if (! Configuration.JAVA_LANG_SYSTEM_EXPLICIT_INITIALIZATION) { |
|
|
initSystemClassLoader(); |
|
|
initSecurityManager(); // Includes getting the class loader. |
|
|
} |
|
|
} |
|
|
|
|
|
static void initLoadLibrary () { |
|
|
// Note that this loadLibrary() takes precedence over the one in Object, |
|
|
// since Object.<clinit> is waiting for System.<clinit> to complete |
|
|
// first; but loading a library twice is harmless. |
|
|
if (Configuration.INIT_LOAD_LIBRARY) |
|
|
loadLibrary("javalang"); |
|
|
|
|
|
} |
|
|
|
|
|
static void initProperties() { |
|
|
Properties defaultProperties = Runtime.defaultProperties; |
|
|
defaultProperties.put("gnu.classpath.home", |
|
|
Configuration.CLASSPATH_HOME); |
|
|
defaultProperties.put("gnu.classpath.version", |
|
|
Configuration.CLASSPATH_VERSION); |
|
|
|
|
|
// Set base URL if not already set. |
|
|
if (defaultProperties.get("gnu.classpath.home.url") == null) |
|
|
defaultProperties.put("gnu.classpath.home.url", |
|
|
"file://" + Configuration.CLASSPATH_HOME + "/lib"); |
|
|
|
|
|
// Set short name if not already set. |
|
|
if (defaultProperties.get("gnu.classpath.vm.shortname") == null) |
|
|
{ |
|
|
String value = defaultProperties.getProperty("java.vm.name"); |
|
|
int index = value.lastIndexOf(' '); |
|
|
if (index != -1) |
|
|
value = value.substring(index + 1); |
|
|
defaultProperties.put("gnu.classpath.vm.shortname", value); |
|
|
} |
|
|
|
|
|
// Network properties |
|
|
if (defaultProperties.get("http.agent") == null) |
|
|
{ |
|
|
String userAgent |
|
|
= ("gnu-classpath/" |
|
|
+ defaultProperties.getProperty("gnu.classpath.version") |
|
|
+ " (" |
|
|
+ defaultProperties.getProperty("gnu.classpath.vm.shortname") |
|
|
+ "/" |
|
|
+ defaultProperties.getProperty("java.vm.version") |
|
|
+ ")"); |
|
|
defaultProperties.put("http.agent", userAgent); |
|
|
} |
|
|
|
|
|
defaultProperties.put("gnu.cpu.endian", |
|
|
VMSystem.isWordsBigEndian() ? "big" : "little"); |
|
|
|
|
|
// Common encoding aliases. See gnu.java.io.EncodingManager. |
|
|
defaultProperties.put("gnu.java.io.encoding_scheme_alias.ISO8859_1", |
|
|
"8859_1"); |
|
|
|
|
|
defaultProperties.put("gnu.java.io.encoding_scheme_alias.ISO-8859-1", |
|
|
"8859_1"); |
|
|
defaultProperties.put("gnu.java.io.encoding_scheme_alias.ISO-8859-2", |
|
|
"8859_2"); |
|
|
defaultProperties.put("gnu.java.io.encoding_scheme_alias.ISO-8859-3", |
|
|
"8859_3"); |
|
|
defaultProperties.put("gnu.java.io.encoding_scheme_alias.ISO-8859-4", |
|
|
"8859_4"); |
|
|
defaultProperties.put("gnu.java.io.encoding_scheme_alias.ISO-8859-5", |
|
|
"8859_5"); |
|
|
defaultProperties.put("gnu.java.io.encoding_scheme_alias.ISO-8859-6", |
|
|
"8859_6"); |
|
|
defaultProperties.put("gnu.java.io.encoding_scheme_alias.ISO-8859-7", |
|
|
"8859_7"); |
|
|
defaultProperties.put("gnu.java.io.encoding_scheme_alias.ISO-8859-8", |
|
|
"8859_8"); |
|
|
defaultProperties.put("gnu.java.io.encoding_scheme_alias.ISO-8859-9", |
|
|
"8859_9"); |
|
|
|
|
|
defaultProperties.put("gnu.java.io.encoding_scheme_alias.iso-8859-1", |
|
|
"8859_1"); |
|
|
defaultProperties.put("gnu.java.io.encoding_scheme_alias.iso-8859-2", |
|
|
"8859_2"); |
|
|
defaultProperties.put("gnu.java.io.encoding_scheme_alias.iso-8859-3", |
|
|
"8859_3"); |
|
|
defaultProperties.put("gnu.java.io.encoding_scheme_alias.iso-8859-4", |
|
|
"8859_4"); |
|
|
defaultProperties.put("gnu.java.io.encoding_scheme_alias.iso-8859-5", |
|
|
"8859_5"); |
|
|
defaultProperties.put("gnu.java.io.encoding_scheme_alias.iso-8859-6", |
|
|
"8859_6"); |
|
|
defaultProperties.put("gnu.java.io.encoding_scheme_alias.iso-8859-7", |
|
|
"8859_7"); |
|
|
defaultProperties.put("gnu.java.io.encoding_scheme_alias.iso-8859-8", |
|
|
"8859_8"); |
|
|
defaultProperties.put("gnu.java.io.encoding_scheme_alias.iso-8859-9", |
|
|
"8859_9"); |
|
|
|
|
|
defaultProperties.put("gnu.java.io.encoding_scheme_alias.iso8859_1", |
|
|
"8859_1"); |
|
|
defaultProperties.put("gnu.java.io.encoding_scheme_alias.iso8859_2", |
|
|
"8859_2"); |
|
|
defaultProperties.put("gnu.java.io.encoding_scheme_alias.iso8859_3", |
|
|
"8859_3"); |
|
|
defaultProperties.put("gnu.java.io.encoding_scheme_alias.iso8859_4", |
|
|
"8859_4"); |
|
|
defaultProperties.put("gnu.java.io.encoding_scheme_alias.iso8859_5", |
|
|
"8859_5"); |
|
|
defaultProperties.put("gnu.java.io.encoding_scheme_alias.iso8859_6", |
|
|
"8859_6"); |
|
|
defaultProperties.put("gnu.java.io.encoding_scheme_alias.iso8859_7", |
|
|
"8859_7"); |
|
|
defaultProperties.put("gnu.java.io.encoding_scheme_alias.iso8859_8", |
|
|
"8859_8"); |
|
|
defaultProperties.put("gnu.java.io.encoding_scheme_alias.iso8859_9", |
|
|
"8859_9"); |
|
|
|
|
|
defaultProperties.put("gnu.java.io.encoding_scheme_alias.iso-latin-1", |
|
|
"8859_1"); |
|
|
defaultProperties.put("gnu.java.io.encoding_scheme_alias.iso-latin-2", |
|
|
"8859_2"); |
|
|
defaultProperties.put("gnu.java.io.encoding_scheme_alias.iso-latin-3", |
|
|
"8859_3"); |
|
|
defaultProperties.put("gnu.java.io.encoding_scheme_alias.iso-latin-4", |
|
|
"8859_4"); |
|
|
defaultProperties.put("gnu.java.io.encoding_scheme_alias.iso-latin-5", |
|
|
"8859_5"); |
|
|
defaultProperties.put("gnu.java.io.encoding_scheme_alias.iso-latin-6", |
|
|
"8859_6"); |
|
|
defaultProperties.put("gnu.java.io.encoding_scheme_alias.iso-latin-7", |
|
|
"8859_7"); |
|
|
defaultProperties.put("gnu.java.io.encoding_scheme_alias.iso-latin-8", |
|
|
"8859_8"); |
|
|
defaultProperties.put("gnu.java.io.encoding_scheme_alias.iso-latin-9", |
|
|
"8859_9"); |
|
|
|
|
|
defaultProperties.put("gnu.java.io.encoding_scheme_alias.latin1", |
|
|
"8859_1"); |
|
|
defaultProperties.put("gnu.java.io.encoding_scheme_alias.latin2", |
|
|
"8859_2"); |
|
|
defaultProperties.put("gnu.java.io.encoding_scheme_alias.latin3", |
|
|
"8859_3"); |
|
|
defaultProperties.put("gnu.java.io.encoding_scheme_alias.latin4", |
|
|
"8859_4"); |
|
|
defaultProperties.put("gnu.java.io.encoding_scheme_alias.latin5", |
|
|
"8859_5"); |
|
|
defaultProperties.put("gnu.java.io.encoding_scheme_alias.latin6", |
|
|
"8859_6"); |
|
|
defaultProperties.put("gnu.java.io.encoding_scheme_alias.latin7", |
|
|
"8859_7"); |
|
|
defaultProperties.put("gnu.java.io.encoding_scheme_alias.latin8", |
|
|
"8859_8"); |
|
|
defaultProperties.put("gnu.java.io.encoding_scheme_alias.latin9", |
|
|
"8859_9"); |
|
|
|
|
|
defaultProperties.put("gnu.java.io.encoding_scheme_alias.UTF-8", "UTF8"); |
|
|
defaultProperties.put("gnu.java.io.encoding_scheme_alias.utf-8", "UTF8"); |
|
|
|
|
|
// XXX FIXME - Cheat a little for ASCII. |
|
|
// Remove when we get a real "ASCII En/Decoder" |
|
|
defaultProperties.put("gnu.java.io.encoding_scheme_alias.ASCII", "8859_1"); |
|
|
defaultProperties.put("gnu.java.io.encoding_scheme_alias.ascii", "8859_1"); |
|
|
defaultProperties.put("gnu.java.io.encoding_scheme_alias.US-ASCII", |
|
|
"8859_1"); |
|
|
defaultProperties.put("gnu.java.io.encoding_scheme_alias.us-ascii", |
|
|
"8859_1"); |
|
|
|
|
|
// 8859_1 is a safe default encoding to use when not explicitly set |
|
|
if (defaultProperties.get("file.encoding") == null) |
|
|
defaultProperties.put("file.encoding", "8859_1"); |
|
|
|
|
|
// XXX FIXME - Temp hack for old systems that set the wrong property |
|
|
if (defaultProperties.get("java.io.tmpdir") == null) |
|
|
defaultProperties.put("java.io.tmpdir", |
|
|
defaultProperties.get("java.tmpdir")); |
|
|
|
|
|
// Note that we use clone here and not new. Some programs assume |
|
|
// that the system properties do not have a parent. |
|
|
properties = (Properties) Runtime.defaultProperties.clone(); |
|
|
} |
|
|
|
|
|
static void initSystemClassLoader() { |
|
|
systemClassLoader = VMClassLoader.getSystemClassLoader(); |
|
|
} |
|
|
|
|
|
static void initSecurityManager () { |
|
|
String secman = properties.getProperty("java.security.manager"); |
|
|
if (secman != null) |
|
|
{ |
|
|
if (secman.equals("") || secman.equals("default")) |
|
|
{ |
|
|
Runtime.securityManager = new java.lang.SecurityManager(); |
|
|
} |
|
|
else |
|
|
{ |
|
|
try |
|
|
{ |
|
|
Class cl = Class.forName(secman, false, systemClassLoader); |
|
|
Runtime.securityManager = (SecurityManager)cl.newInstance(); |
|
|
} |
|
|
catch (Exception x) |
|
|
{ |
|
|
throw (InternalError) |
|
|
new InternalError("Unable to create SecurityManager") |
|
|
.initCause(x); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
99 |
|
|
100 |
/** |
/** |
101 |
* This class is uninstantiable. |
* This class is uninstantiable. |
115 |
*/ |
*/ |
116 |
public static void setIn(InputStream in) |
public static void setIn(InputStream in) |
117 |
{ |
{ |
118 |
SecurityManager sm = Runtime.securityManager; // Be thread-safe. |
SecurityManager sm = SecurityManager.current; // Be thread-safe. |
119 |
if (sm != null) |
if (sm != null) |
120 |
sm.checkPermission(new RuntimePermission("setIO")); |
sm.checkPermission(new RuntimePermission("setIO")); |
121 |
VMSystem.setIn(in); |
VMSystem.setIn(in); |
132 |
*/ |
*/ |
133 |
public static void setOut(PrintStream out) |
public static void setOut(PrintStream out) |
134 |
{ |
{ |
135 |
SecurityManager sm = Runtime.securityManager; // Be thread-safe. |
SecurityManager sm = SecurityManager.current; // Be thread-safe. |
136 |
if (sm != null) |
if (sm != null) |
137 |
sm.checkPermission(new RuntimePermission("setIO")); |
sm.checkPermission(new RuntimePermission("setIO")); |
138 |
|
|
150 |
*/ |
*/ |
151 |
public static void setErr(PrintStream err) |
public static void setErr(PrintStream err) |
152 |
{ |
{ |
153 |
SecurityManager sm = Runtime.securityManager; // Be thread-safe. |
SecurityManager sm = SecurityManager.current; // Be thread-safe. |
154 |
if (sm != null) |
if (sm != null) |
155 |
sm.checkPermission(new RuntimePermission("setIO")); |
sm.checkPermission(new RuntimePermission("setIO")); |
156 |
VMSystem.setErr(err); |
VMSystem.setErr(err); |
172 |
*/ |
*/ |
173 |
public static synchronized void setSecurityManager(SecurityManager sm) |
public static synchronized void setSecurityManager(SecurityManager sm) |
174 |
{ |
{ |
175 |
// Implementation note: the field lives in Runtime because of bootstrap |
// Implementation note: the field lives in SecurityManager because of |
176 |
// initialization issues. This method is synchronized so that no other |
// bootstrap initialization issues. This method is synchronized so that |
177 |
// thread changes it to null before this thread makes the change. |
// no other thread changes it to null before this thread makes the change. |
178 |
if (Runtime.securityManager != null) |
if (SecurityManager.current != null) |
179 |
Runtime.securityManager.checkPermission |
SecurityManager.current.checkPermission |
180 |
(new RuntimePermission("setSecurityManager")); |
(new RuntimePermission("setSecurityManager")); |
181 |
Runtime.securityManager = sm; |
SecurityManager.current = sm; |
182 |
} |
} |
183 |
|
|
184 |
/** |
/** |
189 |
*/ |
*/ |
190 |
public static SecurityManager getSecurityManager() |
public static SecurityManager getSecurityManager() |
191 |
{ |
{ |
192 |
// Implementation note: the field lives in Runtime because of bootstrap |
return SecurityManager.current; |
|
// initialization issues. |
|
|
return Runtime.securityManager; |
|
193 |
} |
} |
194 |
|
|
195 |
/** |
/** |
311 |
*/ |
*/ |
312 |
public static Properties getProperties() |
public static Properties getProperties() |
313 |
{ |
{ |
314 |
SecurityManager sm = Runtime.securityManager; // Be thread-safe. |
SecurityManager sm = SecurityManager.current; // Be thread-safe. |
315 |
if (sm != null) |
if (sm != null) |
316 |
sm.checkPropertiesAccess(); |
sm.checkPropertiesAccess(); |
317 |
return properties; |
return SystemProperties.getProperties(); |
318 |
} |
} |
319 |
|
|
320 |
/** |
/** |
328 |
*/ |
*/ |
329 |
public static void setProperties(Properties properties) |
public static void setProperties(Properties properties) |
330 |
{ |
{ |
331 |
SecurityManager sm = Runtime.securityManager; // Be thread-safe. |
SecurityManager sm = SecurityManager.current; // Be thread-safe. |
332 |
if (sm != null) |
if (sm != null) |
333 |
sm.checkPropertiesAccess(); |
sm.checkPropertiesAccess(); |
334 |
if (properties == null) |
SystemProperties.setProperties(properties); |
|
{ |
|
|
// Note that we use clone here and not new. Some programs |
|
|
// assume that the system properties do not have a parent. |
|
|
properties = (Properties) Runtime.defaultProperties.clone(); |
|
|
} |
|
|
System.properties = properties; |
|
335 |
} |
} |
336 |
|
|
337 |
/** |
/** |
346 |
*/ |
*/ |
347 |
public static String getProperty(String key) |
public static String getProperty(String key) |
348 |
{ |
{ |
349 |
SecurityManager sm = Runtime.securityManager; // Be thread-safe. |
SecurityManager sm = SecurityManager.current; // Be thread-safe. |
350 |
if (sm != null) |
if (sm != null) |
351 |
sm.checkPropertyAccess(key); |
sm.checkPropertyAccess(key); |
352 |
else if (key.length() == 0) |
else if (key.length() == 0) |
353 |
throw new IllegalArgumentException("key can't be empty"); |
throw new IllegalArgumentException("key can't be empty"); |
354 |
return properties.getProperty(key); |
return SystemProperties.getProperty(key); |
355 |
} |
} |
356 |
|
|
357 |
/** |
/** |
367 |
*/ |
*/ |
368 |
public static String getProperty(String key, String def) |
public static String getProperty(String key, String def) |
369 |
{ |
{ |
370 |
SecurityManager sm = Runtime.securityManager; // Be thread-safe. |
SecurityManager sm = SecurityManager.current; // Be thread-safe. |
371 |
if (sm != null) |
if (sm != null) |
372 |
sm.checkPropertyAccess(key); |
sm.checkPropertyAccess(key); |
373 |
return properties.getProperty(key, def); |
return SystemProperties.getProperty(key, def); |
374 |
} |
} |
375 |
|
|
376 |
/** |
/** |
387 |
*/ |
*/ |
388 |
public static String setProperty(String key, String value) |
public static String setProperty(String key, String value) |
389 |
{ |
{ |
390 |
SecurityManager sm = Runtime.securityManager; // Be thread-safe. |
SecurityManager sm = SecurityManager.current; // Be thread-safe. |
391 |
if (sm != null) |
if (sm != null) |
392 |
sm.checkPermission(new PropertyPermission(key, "write")); |
sm.checkPermission(new PropertyPermission(key, "write")); |
393 |
return (String) properties.setProperty(key, value); |
return SystemProperties.setProperty(key, value); |
394 |
} |
} |
395 |
|
|
396 |
/** |
/** |
409 |
{ |
{ |
410 |
if (name == null) |
if (name == null) |
411 |
throw new NullPointerException(); |
throw new NullPointerException(); |
412 |
SecurityManager sm = Runtime.securityManager; // Be thread-safe. |
SecurityManager sm = SecurityManager.current; // Be thread-safe. |
413 |
if (sm != null) |
if (sm != null) |
414 |
sm.checkPermission(new RuntimePermission("getenv." + name)); |
sm.checkPermission(new RuntimePermission("getenv." + name)); |
415 |
return VMSystem.getenv(name); |
return VMSystem.getenv(name); |
515 |
*/ |
*/ |
516 |
public static String mapLibraryName(String libname) |
public static String mapLibraryName(String libname) |
517 |
{ |
{ |
518 |
// XXX Fix this!!!! |
return VMRuntime.mapLibraryName(libname); |
|
return VMRuntime.nativeGetLibname("", libname); |
|
519 |
} |
} |
520 |
|
|
521 |
} // class System |
} // class System |