--- /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. 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