Ignore:
Timestamp:
Apr 27, 2004, 8:39:34 PM (22 years ago)
Author:
bird
Message:

GCC v3.3.3 sources.

Location:
branches/GNU/src/gcc
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/GNU/src/gcc

    • Property svn:ignore
      •  

        old new  
        2626configure.vr
        2727configure.vrs
         28
        2829Makefile
        29 dir.info
        3030lost+found
        3131update.out
  • branches/GNU/src/gcc/libjava/java/lang/System.java

    • Property cvs2svn:cvs-rev changed from 1.1 to 1.1.1.2
    r1390 r1391  
    1 // System.java - System-specific info.
    2 
    3 /* Copyright (C) 1998, 1999, 2000, 2001  Free Software Foundation
    4 
    5    This file is part of libgcj.
    6 
    7 This software is copyrighted work licensed under the terms of the
    8 Libgcj License.  Please consult the file "LIBGCJ_LICENSE" for
    9 details.  */
     1/* System.java -- useful methods to interface with the system
     2   Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003 Free Software Foundation, Inc.
     3
     4This file is part of GNU Classpath.
     5
     6GNU Classpath is free software; you can redistribute it and/or modify
     7it under the terms of the GNU General Public License as published by
     8the Free Software Foundation; either version 2, or (at your option)
     9any later version.
     10
     11GNU Classpath is distributed in the hope that it will be useful, but
     12WITHOUT ANY WARRANTY; without even the implied warranty of
     13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
     14General Public License for more details.
     15
     16You should have received a copy of the GNU General Public License
     17along with GNU Classpath; see the file COPYING.  If not, write to the
     18Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
     1902111-1307 USA.
     20
     21Linking this library statically or dynamically with other modules is
     22making a combined work based on this library.  Thus, the terms and
     23conditions of the GNU General Public License cover the whole
     24combination.
     25
     26As a special exception, the copyright holders of this library give you
     27permission to link this library with independent modules to produce an
     28executable, regardless of the license terms of these independent
     29modules, and to copy and distribute the resulting executable under
     30terms of your choice, provided that you also meet, for each linked
     31independent module, the terms and conditions of the license of that
     32module.  An independent module is a module which is not derived from
     33or based on this library.  If you modify this library, you may extend
     34this exception to your version of the library, but you are not
     35obligated to do so.  If you do not wish to do so, delete this
     36exception statement from your version. */
     37
    1038
    1139package java.lang;
    1240
    13 import java.io.FileDescriptor;
    14 import java.io.FileInputStream;
    15 import java.io.FileOutputStream;
    16 import java.io.FilterInputStream;
    17 import java.io.InputStream;
    18 import java.io.PrintStream;
    19 import java.io.BufferedInputStream;
    20 import java.io.BufferedOutputStream;
     41import java.io.*;
    2142import java.util.Properties;
    2243import java.util.PropertyPermission;
    23 import java.util.TimeZone;
     44import ;
    2445
    2546/**
    26  * @author Tom Tromey <[email protected]>
    27  * @date August 27, 1998
     47 * System represents system-wide resources; things that represent the
     48 * general environment.  As such, all methods are static.
     49 *
     50 * @author John Keiser
     51 * @author Eric Blake <[email protected]>
     52 * @since 1.0
     53 * @status still missing 1.4 functionality
    2854 */
    29 
    30 /* Written using "Java Class Libraries", 2nd edition, ISBN 0-201-31002-3
    31  * "The Java Language Specification", ISBN 0-201-63451-1
    32  * plus online API docs for JDK 1.2 beta from http://www.javasoft.com.
    33  * Status: 1.1.  Some 1.2 methods missing.  Properties code not fully
    34  * implemented.
    35  */
    36 
    3755public final class System
    3856{
    39   public static native void arraycopy (Object src, int srcOffset,
    40                                        Object dst, int dstOffset,
    41                                        int count);
    42 
    43   public static native long currentTimeMillis ();
    44 
    45   // FIXME: When merging with Classpath, remember to remove the call to
    46   // getDefaultTimeZoneId from java.util.Timezone.
    47   private static native String getSystemTimeZone ();
    48 
    49   // Get the System Timezone as reported by the OS.  It should be in
    50   // the form PST8PDT so we'll need to parse it and check that it's valid.
    51   // The result is used to set the user.timezone property in init_properties.
    52   // FIXME: Using the code from Classpath for generating the System
    53   // Timezone IMO is suboptimal because it ignores whether the rules for
    54   // DST match up.
    55   private static String getDefaultTimeZoneId ()
    56   {
    57     String sysTimeZoneId = getSystemTimeZone ();
    58 
    59     // Check if this is a valid timezone.  Make sure the IDs match
    60     // since getTimeZone returns GMT if no match is found.
    61     TimeZone tz = TimeZone.getTimeZone (sysTimeZoneId);
    62     if (tz.getID ().equals (sysTimeZoneId))
    63       return sysTimeZoneId;
    64 
    65     // Check if the base part of sysTimeZoneId is a valid timezone that
    66     // matches with daylight usage and rawOffset.  Make sure the IDs match
    67     // since getTimeZone returns GMT if no match is found.
    68     // First find start of GMT offset info and any Daylight zone name.
    69     int startGMToffset = 0;
    70     int sysTimeZoneIdLength = sysTimeZoneId.length();
    71     for (int i = 0; i < sysTimeZoneIdLength && startGMToffset == 0; i++)
     57  // WARNING: System is a CORE class in the bootstrap cycle. See the comments
     58  // in vm/reference/java/lang/Runtime for implications of this fact.
     59
     60  /**
     61   * Add to the default properties. The field is stored in Runtime, because
     62   * of the bootstrap sequence; but this adds several useful properties to
     63   * the defaults. Once the default is stabilized, it should not be modified;
     64   * instead it is passed as a parent properties for fast setup of the
     65   * defaults when calling <code>setProperties(null)</code>.
     66   */
     67  static
     68  {
     69    // Note that this loadLibrary() takes precedence over the one in Object,
     70    // since Object.<clinit> is waiting for System.<clinit> to complete
     71    // first; but loading a library twice is harmless.
     72    if (Configuration.INIT_LOAD_LIBRARY)
     73      loadLibrary("javalang");
     74
     75    Properties defaultProperties = Runtime.defaultProperties;
     76
     77    // Set base URL if not already set.
     78    if (defaultProperties.get("gnu.classpath.home.url") == null)
     79      defaultProperties.put("gnu.classpath.home.url",
     80                            "file://"
     81                            + defaultProperties.get("gnu.classpath.home")
     82                            + "/lib");
     83
     84    // Set short name if not already set.
     85    if (defaultProperties.get("gnu.classpath.vm.shortname") == null)
    7286      {
    73         if (Character.isDigit (sysTimeZoneId.charAt (i)))
    74           startGMToffset = i;
     87        String value = defaultProperties.getProperty("java.vm.name");
     88        int index = value.lastIndexOf(' ');
     89        if (index != -1)
     90          value = value.substring(index + 1);
     91        defaultProperties.put("gnu.classpath.vm.shortname", value);
    7592      }
    7693
    77     int startDaylightZoneName = 0;
    78     boolean usesDaylight = false;
    79     for (int i = sysTimeZoneIdLength - 1;
    80          i >= 0 && !Character.isDigit (sysTimeZoneId.charAt (i)); --i)
     94    defaultProperties.put("gnu.cpu.endian",
     95                          isWordsBigEndian() ? "big" : "little");
     96    // XXX FIXME - Temp hack for old systems that set the wrong property
     97    if (defaultProperties.get("java.io.tmpdir") == null)
     98      defaultProperties.put("java.io.tmpdir",
     99                            defaultProperties.get("java.tmpdir"));
     100  }
     101
     102  /**
     103   * Stores the current system properties. This can be modified by
     104   * {@link #setProperties(Properties)}, but will never be null, because
     105   * setProperties(null) sucks in the default properties.
     106   */
     107  // Note that we use clone here and not new.  Some programs assume
     108  // that the system properties do not have a parent.
     109  private static Properties properties
     110    = (Properties) Runtime.defaultProperties.clone();
     111
     112  /**
     113   * The standard InputStream. This is assigned at startup and starts its
     114   * life perfectly valid. Although it is marked final, you can change it
     115   * using {@link #setIn(InputStream)} through some hefty VM magic.
     116   *
     117   * <p>This corresponds to the C stdin and C++ cin variables, which
     118   * typically input from the keyboard, but may be used to pipe input from
     119   * other processes or files.  That should all be transparent to you,
     120   * however.
     121   */
     122  public static final InputStream in
     123    = new BufferedInputStream(new FileInputStream(FileDescriptor.in));
     124  /**
     125   * The standard output PrintStream.  This is assigned at startup and
     126   * starts its life perfectly valid. Although it is marked final, you can
     127   * change it using {@link #setOut(PrintStream)} through some hefty VM magic.
     128   *
     129   * <p>This corresponds to the C stdout and C++ cout variables, which
     130   * typically output normal messages to the screen, but may be used to pipe
     131   * output to other processes or files.  That should all be transparent to
     132   * you, however.
     133   */
     134  public static final PrintStream out
     135    = new PrintStream(new BufferedOutputStream(new FileOutputStream(FileDescriptor.out)), true);
     136  /**
     137   * The standard output PrintStream.  This is assigned at startup and
     138   * starts its life perfectly valid. Although it is marked final, you can
     139   * change it using {@link #setOut(PrintStream)} through some hefty VM magic.
     140   *
     141   * <p>This corresponds to the C stderr and C++ cerr variables, which
     142   * typically output error messages to the screen, but may be used to pipe
     143   * output to other processes or files.  That should all be transparent to
     144   * you, however.
     145   */
     146  public static final PrintStream err
     147    = new PrintStream(new BufferedOutputStream(new FileOutputStream(FileDescriptor.err)), true);
     148
     149  /**
     150   * This class is uninstantiable.
     151   */
     152  private System()
     153  {
     154  }
     155
     156  /**
     157   * Set {@link #in} to a new InputStream. This uses some VM magic to change
     158   * a "final" variable, so naturally there is a security check,
     159   * <code>RuntimePermission("setIO")</code>.
     160   *
     161   * @param in the new InputStream
     162   * @throws SecurityException if permission is denied
     163   * @since 1.1
     164   */
     165  public static void setIn(InputStream in)
     166  {
     167    SecurityManager sm = Runtime.securityManager; // Be thread-safe.
     168    if (sm != null)
     169      sm.checkPermission(new RuntimePermission("setIO"));
     170    setIn0(in);
     171  }
     172
     173  /**
     174   * Set {@link #out} to a new PrintStream. This uses some VM magic to change
     175   * a "final" variable, so naturally there is a security check,
     176   * <code>RuntimePermission("setIO")</code>.
     177   *
     178   * @param out the new PrintStream
     179   * @throws SecurityException if permission is denied
     180   * @since 1.1
     181   */
     182  public static void setOut(PrintStream out)
     183  {
     184    SecurityManager sm = Runtime.securityManager; // Be thread-safe.
     185    if (sm != null)
     186      sm.checkPermission(new RuntimePermission("setIO"));
     187    setOut0(out);
     188  }
     189
     190  /**
     191   * Set {@link #err} to a new PrintStream. This uses some VM magic to change
     192   * a "final" variable, so naturally there is a security check,
     193   * <code>RuntimePermission("setIO")</code>.
     194   *
     195   * @param err the new PrintStream
     196   * @throws SecurityException if permission is denied
     197   * @since 1.1
     198   */
     199  public static void setErr(PrintStream err)
     200  {
     201    SecurityManager sm = Runtime.securityManager; // Be thread-safe.
     202    if (sm != null)
     203      sm.checkPermission(new RuntimePermission("setIO"));
     204    setErr0(err);
     205  }
     206
     207  /**
     208   * Set the current SecurityManager. If a security manager already exists,
     209   * then <code>RuntimePermission("setSecurityManager")</code> is checked
     210   * first. Since this permission is denied by the default security manager,
     211   * setting the security manager is often an irreversible action.
     212   *
     213   * <STRONG>Spec Note:</STRONG> Don't ask me, I didn't write it.  It looks
     214   * pretty vulnerable; whoever gets to the gate first gets to set the policy.
     215   * There is probably some way to set the original security manager as a
     216   * command line argument to the VM, but I don't know it.
     217   *
     218   * @param sm the new SecurityManager
     219   * @throws SecurityException if permission is denied
     220   */
     221  public synchronized static void setSecurityManager(SecurityManager sm)
     222  {
     223    // Implementation note: the field lives in Runtime because of bootstrap
     224    // initialization issues. This method is synchronized so that no other
     225    // thread changes it to null before this thread makes the change.
     226    if (Runtime.securityManager != null)
     227      Runtime.securityManager.checkPermission
     228        (new RuntimePermission("setSecurityManager"));
     229    Runtime.securityManager = sm;
     230  }
     231
     232  /**
     233   * Get the current SecurityManager. If the SecurityManager has not been
     234   * set yet, then this method returns null.
     235   *
     236   * @return the current SecurityManager, or null
     237   */
     238  public static SecurityManager getSecurityManager()
     239  {
     240    // Implementation note: the field lives in Runtime because of bootstrap
     241    // initialization issues.
     242    return Runtime.securityManager;
     243  }
     244
     245  /**
     246   * Get the current time, measured in the number of milliseconds from the
     247   * beginning of Jan. 1, 1970. This is gathered from the system clock, with
     248   * any attendant incorrectness (it may be timezone dependent).
     249   *
     250   * @return the current time
     251   * @see java.util.Date
     252   */
     253  public static native long currentTimeMillis();
     254
     255  /**
     256   * Copy one array onto another from <code>src[srcStart]</code> ...
     257   * <code>src[srcStart+len-1]</code> to <code>dest[destStart]</code> ...
     258   * <code>dest[destStart+len-1]</code>. First, the arguments are validated:
     259   * neither array may be null, they must be of compatible types, and the
     260   * start and length must fit within both arrays. Then the copying starts,
     261   * and proceeds through increasing slots.  If src and dest are the same
     262   * array, this will appear to copy the data to a temporary location first.
     263   * An ArrayStoreException in the middle of copying will leave earlier
     264   * elements copied, but later elements unchanged.
     265   *
     266   * @param src the array to copy elements from
     267   * @param srcStart the starting position in src
     268   * @param dest the array to copy elements to
     269   * @param destStart the starting position in dest
     270   * @param len the number of elements to copy
     271   * @throws NullPointerException if src or dest is null
     272   * @throws ArrayStoreException if src or dest is not an array, if they are
     273   *         not compatible array types, or if an incompatible runtime type
     274   *         is stored in dest
     275   * @throws IndexOutOfBoundsException if len is negative, or if the start or
     276   *         end copy position in either array is out of bounds
     277   */
     278  public static native void arraycopy(Object src, int srcStart,
     279                                      Object dest, int destStart, int len);
     280
     281  /**
     282   * Get a hash code computed by the VM for the Object. This hash code will
     283   * be the same as Object's hashCode() method.  It is usually some
     284   * convolution of the pointer to the Object internal to the VM.  It
     285   * follows standard hash code rules, in that it will remain the same for a
     286   * given Object for the lifetime of that Object.
     287   *
     288   * @param o the Object to get the hash code for
     289   * @return the VM-dependent hash code for this Object
     290   * @since 1.1
     291   */
     292  public static native int identityHashCode(Object o);
     293
     294  /**
     295   * Get all the system properties at once. A security check may be performed,
     296   * <code>checkPropertiesAccess</code>. Note that a security manager may
     297   * allow getting a single property, but not the entire group.
     298   *
     299   * <p>The required properties include:
     300   * <dl>
     301   * <dt>java.version         <dd>Java version number
     302   * <dt>java.vendor          <dd>Java vendor specific string
     303   * <dt>java.vendor.url      <dd>Java vendor URL
     304   * <dt>java.home            <dd>Java installation directory
     305   * <dt>java.vm.specification.version <dd>VM Spec version
     306   * <dt>java.vm.specification.vendor  <dd>VM Spec vendor
     307   * <dt>java.vm.specification.name    <dd>VM Spec name
     308   * <dt>java.vm.version      <dd>VM implementation version
     309   * <dt>java.vm.vendor       <dd>VM implementation vendor
     310   * <dt>java.vm.name         <dd>VM implementation name
     311   * <dt>java.specification.version    <dd>Java Runtime Environment version
     312   * <dt>java.specification.vendor     <dd>Java Runtime Environment vendor
     313   * <dt>java.specification.name       <dd>Java Runtime Environment name
     314   * <dt>java.class.version   <dd>Java class version number
     315   * <dt>java.class.path      <dd>Java classpath
     316   * <dt>java.library.path    <dd>Path for finding Java libraries
     317   * <dt>java.io.tmpdir       <dd>Default temp file path
     318   * <dt>java.compiler        <dd>Name of JIT to use
     319   * <dt>java.ext.dirs        <dd>Java extension path
     320   * <dt>os.name              <dd>Operating System Name
     321   * <dt>os.arch              <dd>Operating System Architecture
     322   * <dt>os.version           <dd>Operating System Version
     323   * <dt>file.separator       <dd>File separator ("/" on Unix)
     324   * <dt>path.separator       <dd>Path separator (":" on Unix)
     325   * <dt>line.separator       <dd>Line separator ("\n" on Unix)
     326   * <dt>user.name            <dd>User account name
     327   * <dt>user.home            <dd>User home directory
     328   * <dt>user.dir             <dd>User's current working directory
     329   * </dl>
     330   *
     331   * In addition, gnu defines several other properties, where ? stands for
     332   * each character in '0' through '9':
     333   * <dl>
     334   * <dl> gnu.classpath.vm.shortname <dd> Succinct version of the VM name;
     335   *      used for finding property files in file system
     336   * <dl> gnu.classpath.home.url <dd> Base URL; used for finding
     337   *      property files in file system
     338   * <dt> gnu.cpu.endian      <dd>big or little
     339   * <dt> gnu.java.io.encoding_scheme_alias.ISO-8859-?   <dd>8859_?
     340   * <dt> gnu.java.io.encoding_scheme_alias.iso-8859-?   <dd>8859_?
     341   * <dt> gnu.java.io.encoding_scheme_alias.iso8859_?    <dd>8859_?
     342   * <dt> gnu.java.io.encoding_scheme_alias.iso-latin-_? <dd>8859_?
     343   * <dt> gnu.java.io.encoding_scheme_alias.latin?       <dd>8859_?
     344   * <dt> gnu.java.io.encoding_scheme_alias.UTF-8        <dd>UTF8
     345   * <dt> gnu.java.io.encoding_scheme_alias.utf-8        <dd>UTF8
     346   * </dl>
     347   *
     348   * @return the system properties, will never be null
     349   * @throws SecurityException if permission is denied
     350   */
     351  public static Properties getProperties()
     352  {
     353    SecurityManager sm = Runtime.securityManager; // Be thread-safe.
     354    if (sm != null)
     355      sm.checkPropertiesAccess();
     356    return properties;
     357  }
     358
     359  /**
     360   * Set all the system properties at once. A security check may be performed,
     361   * <code>checkPropertiesAccess</code>. Note that a security manager may
     362   * allow setting a single property, but not the entire group. An argument
     363   * of null resets the properties to the startup default.
     364   *
     365   * @param properties the new set of system properties
     366   * @throws SecurityException if permission is denied
     367   */
     368  public static void setProperties(Properties properties)
     369  {
     370    SecurityManager sm = Runtime.securityManager; // Be thread-safe.
     371    if (sm != null)
     372      sm.checkPropertiesAccess();
     373    if (properties == null)
    81374      {
    82         startDaylightZoneName = i;
     375        // Note that we use clone here and not new.  Some programs
     376        // assume that the system properties do not have a parent.
     377        properties = (Properties) Runtime.defaultProperties.clone();
    83378      }
    84     if (startDaylightZoneName > 0)
    85       usesDaylight = true;
    86 
    87     int GMToffset = Integer.parseInt (startDaylightZoneName == 0 ?
    88       sysTimeZoneId.substring (startGMToffset) :
    89       sysTimeZoneId.substring (startGMToffset, startDaylightZoneName));
    90 
    91     // Offset could be in hours or seconds.  Convert to millis.
    92     if (GMToffset < 24)
    93       GMToffset *= 60 * 60;
    94     GMToffset *= -1000;
    95 
    96     String tzBasename = sysTimeZoneId.substring (0, startGMToffset);
    97     tz = TimeZone.getTimeZone (tzBasename);
    98     if (tz.getID ().equals (tzBasename) && tz.getRawOffset () == GMToffset)
    99       {
    100         boolean tzUsesDaylight = tz.useDaylightTime ();
    101         if (usesDaylight && tzUsesDaylight || !usesDaylight && !tzUsesDaylight)
    102           return tzBasename;
    103       }
    104  
    105     // If no match, see if a valid timezone has the same attributes as this
    106     // and then use it instead.
    107     String[] IDs = TimeZone.getAvailableIDs (GMToffset);
    108     for (int i = 0; i < IDs.length; ++i)
    109       {
    110         // FIXME: The daylight savings rules may not match the rules
    111         // for the desired zone.
    112         boolean IDusesDaylight =
    113           TimeZone.getTimeZone (IDs[i]).useDaylightTime ();
    114         if (usesDaylight && IDusesDaylight || !usesDaylight && !IDusesDaylight)
    115           return IDs[i];
    116       }
    117 
    118     // If all else fails, return null.
    119     return null;
    120   }
    121 
    122   public static void exit (int status)
     379    System.properties = properties;
     380  }
     381
     382  /**
     383   * Get a single system property by name. A security check may be performed,
     384   * <code>checkPropertyAccess(key)</code>.
     385   *
     386   * @param key the name of the system property to get
     387   * @return the property, or null if not found
     388   * @throws SecurityException if permission is denied
     389   * @throws NullPointerException if key is null
     390   * @throws IllegalArgumentException if key is ""
     391   */
     392  public static String getProperty(String key)
     393  {
     394    SecurityManager sm = Runtime.securityManager; // Be thread-safe.
     395    if (sm != null)
     396      sm.checkPropertyAccess(key);
     397    else if (key.length() == 0)
     398      throw new IllegalArgumentException("key can't be empty");
     399    return properties.getProperty(key);
     400  }
     401
     402  /**
     403   * Get a single system property by name. A security check may be performed,
     404   * <code>checkPropertyAccess(key)</code>.
     405   *
     406   * @param key the name of the system property to get
     407   * @param def the default
     408   * @return the property, or def if not found
     409   * @throws SecurityException if permission is denied
     410   * @throws NullPointerException if key is null
     411   * @throws IllegalArgumentException if key is ""
     412   */
     413  public static String getProperty(String key, String def)
     414  {
     415    SecurityManager sm = Runtime.securityManager; // Be thread-safe.
     416    if (sm != null)
     417      sm.checkPropertyAccess(key);
     418    return properties.getProperty(key, def);
     419  }
     420
     421  /**
     422   * Set a single system property by name. A security check may be performed,
     423   * <code>checkPropertyAccess(key, "write")</code>.
     424   *
     425   * @param key the name of the system property to set
     426   * @param value the new value
     427   * @return the previous value, or null
     428   * @throws SecurityException if permission is denied
     429   * @throws NullPointerException if key is null
     430   * @throws IllegalArgumentException if key is ""
     431   * @since 1.2
     432   */
     433  public static String setProperty(String key, String value)
     434  {
     435    SecurityManager sm = Runtime.securityManager; // Be thread-safe.
     436    if (sm != null)
     437      sm.checkPermission(new PropertyPermission(key, "write"));
     438    return (String) properties.setProperty(key, value);
     439  }
     440
     441  /**
     442   * This used to get an environment variable, but following Sun's lead,
     443   * it now throws an Error. Use <code>getProperty</code> instead.
     444   *
     445   * @param name the name of the environment variable
     446   * @return this does not return
     447   * @throws Error this is not supported
     448   * @deprecated use {@link #getProperty(String)}; getenv is not supported
     449   */
     450  public static String getenv(String name)
     451  {
     452    throw new Error("getenv no longer supported, use properties instead: "
     453                    + name);
     454  }
     455
     456  /**
     457   * Terminate the Virtual Machine. This just calls
     458   * <code>Runtime.getRuntime().exit(status)</code>, and never returns.
     459   * Obviously, a security check is in order, <code>checkExit</code>.
     460   *
     461   * @param status the exit status; by convention non-zero is abnormal
     462   * @throws SecurityException if permission is denied
     463   * @see Runtime#exit(int)
     464   */
     465  public static void exit(int status)
    123466  {
    124467    Runtime.getRuntime().exit(status);
    125468  }
    126469
    127   public static void gc ()
     470  /**
     471   * Calls the garbage collector. This is only a hint, and it is up to the
     472   * implementation what this hint suggests, but it usually causes a
     473   * best-effort attempt to reclaim unused memory from discarded objects.
     474   * This calls <code>Runtime.getRuntime().gc()</code>.
     475   *
     476   * @see Runtime#gc()
     477   */
     478  public static void gc()
    128479  {
    129480    Runtime.getRuntime().gc();
    130481  }
    131482
    132   // Marked deprecated in 1.1.  We implement what the JCL book says.
    133   public static String getenv (String name)
    134   {
    135     throw new Error ();
    136   }
    137 
    138   private static native void init_properties ();
    139 
    140   public static Properties getProperties ()
    141   {
    142     if (secman != null)
    143       secman.checkPropertiesAccess();
    144     if (properties == null)
    145       init_properties ();
    146     return properties;
    147   }
    148 
    149   public static String getProperty (String property)
    150   {
    151     if (secman != null)
    152       secman.checkPropertyAccess(property);
    153     if (properties == null)
    154       init_properties ();
    155     return properties.getProperty(property);
    156   }
    157 
    158   public static String getProperty (String property, String defval)
    159   {
    160     if (secman != null)
    161       secman.checkPropertyAccess(property);
    162     if (properties == null)
    163       init_properties ();
    164     return properties.getProperty(property, defval);
    165   }
    166 
    167   public static SecurityManager getSecurityManager ()
    168   {
    169     return secman;
    170   }
    171 
    172   public static native int identityHashCode (Object obj);
    173 
    174   public static void load (String pathname)
    175   {
    176     Runtime.getRuntime().load(pathname);
    177   }
    178 
    179   public static void loadLibrary (String libname)
     483  /**
     484   * Runs object finalization on pending objects. This is only a hint, and
     485   * it is up to the implementation what this hint suggests, but it usually
     486   * causes a best-effort attempt to run finalizers on all objects ready
     487   * to be reclaimed. This calls
     488   * <code>Runtime.getRuntime().runFinalization()</code>.
     489   *
     490   * @see Runtime#runFinalization()
     491   */
     492  public static void runFinalization()
     493  {
     494    Runtime.getRuntime().runFinalization();
     495  }
     496
     497  /**
     498   * Tell the Runtime whether to run finalization before exiting the
     499   * JVM.  This is inherently unsafe in multi-threaded applications,
     500   * since it can force initialization on objects which are still in use
     501   * by live threads, leading to deadlock; therefore this is disabled by
     502   * default. There may be a security check, <code>checkExit(0)</code>. This
     503   * calls <code>Runtime.getRuntime().runFinalizersOnExit()</code>.
     504   *
     505   * @param finalizeOnExit whether to run finalizers on exit
     506   * @throws SecurityException if permission is denied
     507   * @see Runtime#runFinalizersOnExit()
     508   * @since 1.1
     509   * @deprecated never rely on finalizers to do a clean, thread-safe,
     510   *             mop-up from your code
     511   */
     512  public static void runFinalizersOnExit(boolean finalizeOnExit)
     513  {
     514    Runtime.getRuntime().runFinalizersOnExit(finalizeOnExit);
     515  }
     516
     517  /**
     518   * Load a code file using its explicit system-dependent filename. A security
     519   * check may be performed, <code>checkLink</code>. This just calls
     520   * <code>Runtime.getRuntime().load(filename)</code>.
     521   *
     522   * @param filename the code file to load
     523   * @throws SecurityException if permission is denied
     524   * @throws UnsatisfiedLinkError if the file cannot be loaded
     525   * @see Runtime#load(String)
     526   */
     527  public static void load(String filename)
     528  {
     529    Runtime.getRuntime().load(filename);
     530  }
     531
     532  /**
     533   * Load a library using its explicit system-dependent filename. A security
     534   * check may be performed, <code>checkLink</code>. This just calls
     535   * <code>Runtime.getRuntime().load(filename)</code>.
     536   *
     537   * @param libname the library file to load
     538   * @throws SecurityException if permission is denied
     539   * @throws UnsatisfiedLinkError if the file cannot be loaded
     540   * @see Runtime#load(String)
     541   */
     542  public static void loadLibrary(String libname)
    180543  {
    181544    Runtime.getRuntime().loadLibrary(libname);
    182545  }
    183546
    184   public static void runFinalization ()
    185   {
    186     Runtime.getRuntime().runFinalization();
    187   }
    188 
    189   // Marked as deprecated in 1.2.
    190   public static void runFinalizersOnExit (boolean run)
    191   {
    192     Runtime.getRuntime().runFinalizersOnExit(run);
    193   }
    194 
    195   private static void checkSetIO ()
    196   {
    197     // In 1.1, we are supposed to call checkExec, but the argument is
    198     // not specified.  In 1.2, we are supposed to use checkPermission,
    199     // which doesn't exist in 1.1.
    200     if (secman != null)
    201       secman.checkExec("");
    202   }
    203 
    204   public static native void setErr (PrintStream newErr);
    205   public static native void setIn (InputStream newIn);
    206   public static native void setOut (PrintStream newOut);
    207 
    208   public static void setProperties (Properties props)
    209   {
    210     if (secman != null)
    211       secman.checkPropertiesAccess();
    212     synchronized (System.class)
    213     {
    214       properties = props;
    215     }
    216   }
    217 
    218   public static String setProperty (String key, String value)
    219   {
    220     if (secman != null)
    221       secman.checkPermission (new PropertyPermission (key, "write"));
    222     if (properties == null)
    223       init_properties ();
    224     return (String) properties.setProperty (key, value);
    225   }
    226 
    227   // TODO 1.2.
    228   // public static String mapLibraryName (String libname);
    229 
    230   public static void setSecurityManager (SecurityManager s)
    231   {
    232     if (secman != null)
    233       secman.checkPermission(new RuntimePermission("setSecurityManager"));
    234     secman = s;
    235   }
    236 
    237   // Public data.
    238   public static final InputStream in = new BufferedInputStream (new FileInputStream (FileDescriptor.in));
    239 
    240   public static final PrintStream out = new PrintStream (new BufferedOutputStream (new FileOutputStream (FileDescriptor.out)), true);
    241 
    242   public static final PrintStream err = new PrintStream (new BufferedOutputStream (new FileOutputStream (FileDescriptor.err)), true);
    243 
    244   // Don't allow System objects to be made.
    245   private System ()
    246   {
    247   }
    248 
    249   // Private data.
    250   private static SecurityManager secman = null;
    251   private static Properties properties = null;
    252 }
     547  /**
     548   * Convert a library name to its platform-specific variant.
     549   *
     550   * @param libname the library name, as used in <code>loadLibrary</code>
     551   * @return the platform-specific mangling of the name
     552   * @since 1.2
     553   */
     554  public static String mapLibraryName(String libname)
     555  {
     556    // XXX Fix this!!!!
     557    return Runtime.nativeGetLibname("", libname);
     558  }
     559
     560  /**
     561   * Detect big-endian systems.
     562   *
     563   * @return true if the system is big-endian.
     564   */
     565  static native boolean isWordsBigEndian();
     566
     567  /**
     568   * Set {@link #in} to a new InputStream.
     569   *
     570   * @param in the new InputStream
     571   * @see #setIn(InputStream)
     572   */
     573  private static native void setIn0(InputStream in);
     574
     575  /**
     576   * Set {@link #out} to a new PrintStream.
     577   *
     578   * @param out the new PrintStream
     579   * @see #setOut(PrintStream)
     580   */
     581  private static native void setOut0(PrintStream out);
     582
     583  /**
     584   * Set {@link #err} to a new PrintStream.
     585   *
     586   * @param err the new PrintStream
     587   * @see #setErr(PrintStream)
     588   */
     589  private static native void setErr0(PrintStream err);
     590} // class System
Note: See TracChangeset for help on using the changeset viewer.