--- /home/tromey/gnu/Nightly/classpath/classpath/java/lang/System.java 2004-11-14 02:20:08.000000000 -0700 +++ java/lang/System.java 2004-10-28 02:16:10.000000000 -0600 @@ -41,6 +41,11 @@ import gnu.classpath.Configuration; +import java.io.BufferedInputStream; +import java.io.BufferedOutputStream; +import java.io.FileDescriptor; +import java.io.FileInputStream; +import java.io.FileOutputStream; import java.io.InputStream; import java.io.PrintStream; import java.util.Properties; @@ -61,59 +66,6 @@ // in vm/reference/java/lang/Runtime for implications of this fact. /** - * 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; - - /** - * The standard InputStream. This is assigned at startup and starts its - * life perfectly valid. Although it is marked final, you can change it - * using {@link #setIn(InputStream)} through some hefty VM magic. - * - *

This corresponds to the C stdin and C++ cin variables, which - * typically input from the keyboard, but may be used to pipe input from - * other processes or files. That should all be transparent to you, - * however. - */ - public static final InputStream in; - - /** - * The standard output PrintStream. This is assigned at startup and - * starts its life perfectly valid. Although it is marked final, you can - * change it using {@link #setOut(PrintStream)} through some hefty VM magic. - * - *

This corresponds to the C stdout and C++ cout variables, which - * typically output normal messages to the screen, but may be used to pipe - * output to other processes or files. That should all be transparent to - * you, however. - */ - public static final PrintStream out; - - /** - * The standard output PrintStream. This is assigned at startup and - * starts its life perfectly valid. Although it is marked final, you can - * change it using {@link #setErr(PrintStream)} through some hefty VM magic. - * - *

This corresponds to the C stderr and C++ cerr variables, which - * typically output error messages to the screen, but may be used to pipe - * output to other processes or files. That should all be transparent to - * you, however. - */ - public static final PrintStream err; - - /** * 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; @@ -122,42 +74,20 @@ */ 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. is waiting for System. 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"); + "file://" + + defaultProperties.get("gnu.classpath.home") + + "/lib"); // Set short name if not already set. if (defaultProperties.get("gnu.classpath.vm.shortname") == null) @@ -184,161 +114,64 @@ } defaultProperties.put("gnu.cpu.endian", - VMSystem.isWordsBigEndian() ? "big" : "little"); + 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"); + // GCJ LOCAL: Classpath sets common encoding aliases here. + // Since we don't (yet) have gnu.java.io.EncodingManager, these + // are a waste of time and just slow down system startup. // 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(); - } + /** + * 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. + */ + // Note that we use clone here and not new. Some programs assume + // that the system properties do not have a parent. + static Properties properties + = (Properties) Runtime.defaultProperties.clone(); - 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); - } - } - } - } + /** + * The standard InputStream. This is assigned at startup and starts its + * life perfectly valid. Although it is marked final, you can change it + * using {@link #setIn(InputStream)} through some hefty VM magic. + * + *

This corresponds to the C stdin and C++ cin variables, which + * typically input from the keyboard, but may be used to pipe input from + * other processes or files. That should all be transparent to you, + * however. + */ + public static final InputStream in + = new BufferedInputStream(new FileInputStream(FileDescriptor.in)); + /** + * The standard output PrintStream. This is assigned at startup and + * starts its life perfectly valid. Although it is marked final, you can + * change it using {@link #setOut(PrintStream)} through some hefty VM magic. + * + *

This corresponds to the C stdout and C++ cout variables, which + * typically output normal messages to the screen, but may be used to pipe + * output to other processes or files. That should all be transparent to + * you, however. + */ + public static final PrintStream out + = new PrintStream(new BufferedOutputStream(new FileOutputStream(FileDescriptor.out)), true); + /** + * The standard output PrintStream. This is assigned at startup and + * starts its life perfectly valid. Although it is marked final, you can + * change it using {@link #setErr(PrintStream)} through some hefty VM magic. + * + *

This corresponds to the C stderr and C++ cerr variables, which + * typically output error messages to the screen, but may be used to pipe + * output to other processes or files. That should all be transparent to + * you, however. + */ + public static final PrintStream err + = new PrintStream(new BufferedOutputStream(new FileOutputStream(FileDescriptor.err)), true); /** * This class is uninstantiable. @@ -361,7 +194,7 @@ SecurityManager sm = Runtime.securityManager; // Be thread-safe. if (sm != null) sm.checkPermission(new RuntimePermission("setIO")); - VMSystem.setIn(in); + setIn0(in); } /** @@ -379,7 +212,7 @@ if (sm != null) sm.checkPermission(new RuntimePermission("setIO")); - VMSystem.setOut(out); + setOut0(out); } /** @@ -396,7 +229,7 @@ SecurityManager sm = Runtime.securityManager; // Be thread-safe. if (sm != null) sm.checkPermission(new RuntimePermission("setIO")); - VMSystem.setErr(err); + setErr0(err); } /** @@ -413,7 +246,7 @@ * @param sm the new SecurityManager * @throws SecurityException if permission is denied */ - public static synchronized void setSecurityManager(SecurityManager sm) + public synchronized static void setSecurityManager(SecurityManager sm) { // Implementation note: the field lives in Runtime because of bootstrap // initialization issues. This method is synchronized so that no other @@ -445,10 +278,7 @@ * @return the current time * @see java.util.Date */ - public static long currentTimeMillis() - { - return VMSystem.currentTimeMillis(); - } + public static native long currentTimeMillis(); /** * Copy one array onto another from src[srcStart] ... @@ -473,11 +303,8 @@ * @throws IndexOutOfBoundsException if len is negative, or if the start or * end copy position in either array is out of bounds */ - public static void arraycopy(Object src, int srcStart, - Object dest, int destStart, int len) - { - VMSystem.arraycopy(src, srcStart, dest, destStart, len); - } + public static native void arraycopy(Object src, int srcStart, + Object dest, int destStart, int len); /** * Get a hash code computed by the VM for the Object. This hash code will @@ -490,10 +317,7 @@ * @return the VM-dependent hash code for this Object * @since 1.1 */ - public static int identityHashCode(Object o) - { - return VMSystem.identityHashCode(o); - } + public static native int identityHashCode(Object o); /** * Get all the system properties at once. A security check may be performed, @@ -648,13 +472,10 @@ * Gets the value of an environment variable. * * @param name the name of the environment variable - * @return the string value of the variable or null when the - * environment variable is not defined. + * @return the string value of the variable * @throws NullPointerException * @throws SecurityException if permission is denied * @since 1.5 - * @specnote This method was deprecated in some JDK releases, but - * was restored in 1.5. */ public static String getenv(String name) { @@ -662,8 +483,8 @@ throw new NullPointerException(); SecurityManager sm = Runtime.securityManager; // Be thread-safe. if (sm != null) - sm.checkPermission(new RuntimePermission("getenv." + name)); - return VMSystem.getenv(name); + sm.checkPermission(new RuntimePermission("getenv."+name)); + return getenv0(name); } /** @@ -713,7 +534,7 @@ * since it can force initialization on objects which are still in use * by live threads, leading to deadlock; therefore this is disabled by * default. There may be a security check, checkExit(0). This - * calls Runtime.runFinalizersOnExit(). + * calls Runtime.getRuntime().runFinalizersOnExit(). * * @param finalizeOnExit whether to run finalizers on exit * @throws SecurityException if permission is denied @@ -724,7 +545,7 @@ */ public static void runFinalizersOnExit(boolean finalizeOnExit) { - Runtime.runFinalizersOnExit(finalizeOnExit); + Runtime.getRuntime().runFinalizersOnExit(finalizeOnExit); } /** @@ -767,7 +588,44 @@ public static String mapLibraryName(String libname) { // XXX Fix this!!!! - return VMRuntime.nativeGetLibname("", libname); + return Runtime.nativeGetLibname("", libname); } + /** + * Detect big-endian systems. + * + * @return true if the system is big-endian. + */ + static native boolean isWordsBigEndian(); + + /** + * Set {@link #in} to a new InputStream. + * + * @param in the new InputStream + * @see #setIn(InputStream) + */ + private static native void setIn0(InputStream in); + + /** + * Set {@link #out} to a new PrintStream. + * + * @param out the new PrintStream + * @see #setOut(PrintStream) + */ + private static native void setOut0(PrintStream out); + + /** + * Set {@link #err} to a new PrintStream. + * + * @param err the new PrintStream + * @see #setErr(PrintStream) + */ + private static native void setErr0(PrintStream err); + + /** + * Gets the value of an environment variable. + * + * @see #getenv(String) + */ + static native String getenv0(String name); } // class System