/[classpath]/classpath/java/lang/System.java
ViewVC logotype

Diff of /classpath/java/lang/System.java

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.38.2.7 by gnu_andrew, Sun Jan 16 02:14:48 2005 UTC revision 1.38.2.8 by gnu_andrew, Sun Jan 16 15:15:12 2005 UTC
# Line 39  exception statement from your version. * Line 39  exception statement from your version. *
39    
40  package java.lang;  package java.lang;
41    
42  import gnu.classpath.Configuration;  import gnu.classpath.SystemProperties;
43    import gnu.classpath.VMStackWalker;
44    
45  import java.io.InputStream;  import java.io.InputStream;
46  import java.io.PrintStream;  import java.io.PrintStream;
# Line 62  public final class System Line 63  public final class System
63    // in vm/reference/java/lang/Runtime for implications of this fact.    // in vm/reference/java/lang/Runtime for implications of this fact.
64    
65    /**    /**
    * 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;  
   
   /**  
66     * The standard InputStream. This is assigned at startup and starts its     * The standard InputStream. This is assigned at startup and starts its
67     * life perfectly valid. Although it is marked final, you can change it     * life perfectly valid. Although it is marked final, you can change it
68     * using {@link #setIn(InputStream)} through some hefty VM magic.     * using {@link #setIn(InputStream)} through some hefty VM magic.
# Line 88  public final class System Line 72  public final class System
72     * other processes or files.  That should all be transparent to you,     * other processes or files.  That should all be transparent to you,
73     * however.     * however.
74     */     */
75    public static final InputStream in;    public static final InputStream in = VMSystem.makeStandardInputStream();
76    
77    /**    /**
78     * The standard output PrintStream.  This is assigned at startup and     * The standard output PrintStream.  This is assigned at startup and
# Line 100  public final class System Line 84  public final class System
84     * output to other processes or files.  That should all be transparent to     * output to other processes or files.  That should all be transparent to
85     * you, however.     * you, however.
86     */     */
87    public static final PrintStream out;    public static final PrintStream out = VMSystem.makeStandardOutputStream();
88    
89    /**    /**
90     * The standard output PrintStream.  This is assigned at startup and     * The standard output PrintStream.  This is assigned at startup and
# Line 112  public final class System Line 96  public final class System
96     * output to other processes or files.  That should all be transparent to     * output to other processes or files.  That should all be transparent to
97     * you, however.     * you, however.
98     */     */
99    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);  
               }  
           }  
       }  
   }  
100    
101    /**    /**
102     * This class is uninstantiable.     * This class is uninstantiable.
# Line 359  public final class System Line 116  public final class System
116     */     */
117    public static void setIn(InputStream in)    public static void setIn(InputStream in)
118    {    {
119      SecurityManager sm = Runtime.securityManager; // Be thread-safe.      SecurityManager sm = SecurityManager.current; // Be thread-safe.
120      if (sm != null)      if (sm != null)
121        sm.checkPermission(new RuntimePermission("setIO"));        sm.checkPermission(new RuntimePermission("setIO"));
122      VMSystem.setIn(in);      VMSystem.setIn(in);
# Line 376  public final class System Line 133  public final class System
133     */     */
134    public static void setOut(PrintStream out)    public static void setOut(PrintStream out)
135    {    {
136      SecurityManager sm = Runtime.securityManager; // Be thread-safe.      SecurityManager sm = SecurityManager.current; // Be thread-safe.
137      if (sm != null)      if (sm != null)
138        sm.checkPermission(new RuntimePermission("setIO"));        sm.checkPermission(new RuntimePermission("setIO"));
139            
# Line 394  public final class System Line 151  public final class System
151     */     */
152    public static void setErr(PrintStream err)    public static void setErr(PrintStream err)
153    {    {
154      SecurityManager sm = Runtime.securityManager; // Be thread-safe.      SecurityManager sm = SecurityManager.current; // Be thread-safe.
155      if (sm != null)      if (sm != null)
156        sm.checkPermission(new RuntimePermission("setIO"));        sm.checkPermission(new RuntimePermission("setIO"));
157      VMSystem.setErr(err);      VMSystem.setErr(err);
# Line 416  public final class System Line 173  public final class System
173     */     */
174    public static synchronized void setSecurityManager(SecurityManager sm)    public static synchronized void setSecurityManager(SecurityManager sm)
175    {    {
176      // Implementation note: the field lives in Runtime because of bootstrap      // Implementation note: the field lives in SecurityManager because of
177      // initialization issues. This method is synchronized so that no other      // bootstrap initialization issues. This method is synchronized so that
178      // thread changes it to null before this thread makes the change.      // no other thread changes it to null before this thread makes the change.
179      if (Runtime.securityManager != null)      if (SecurityManager.current != null)
180        Runtime.securityManager.checkPermission        SecurityManager.current.checkPermission
181          (new RuntimePermission("setSecurityManager"));          (new RuntimePermission("setSecurityManager"));
182      Runtime.securityManager = sm;      SecurityManager.current = sm;
183    }    }
184    
185    /**    /**
# Line 433  public final class System Line 190  public final class System
190     */     */
191    public static SecurityManager getSecurityManager()    public static SecurityManager getSecurityManager()
192    {    {
193      // Implementation note: the field lives in Runtime because of bootstrap      return SecurityManager.current;
     // initialization issues.  
     return Runtime.securityManager;  
194    }    }
195    
196    /**    /**
# Line 557  public final class System Line 312  public final class System
312     */     */
313    public static Properties getProperties()    public static Properties getProperties()
314    {    {
315      SecurityManager sm = Runtime.securityManager; // Be thread-safe.      SecurityManager sm = SecurityManager.current; // Be thread-safe.
316      if (sm != null)      if (sm != null)
317        sm.checkPropertiesAccess();        sm.checkPropertiesAccess();
318      return properties;      return SystemProperties.getProperties();
319    }    }
320    
321    /**    /**
# Line 574  public final class System Line 329  public final class System
329     */     */
330    public static void setProperties(Properties properties)    public static void setProperties(Properties properties)
331    {    {
332      SecurityManager sm = Runtime.securityManager; // Be thread-safe.      SecurityManager sm = SecurityManager.current; // Be thread-safe.
333      if (sm != null)      if (sm != null)
334        sm.checkPropertiesAccess();        sm.checkPropertiesAccess();
335      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;  
336    }    }
337    
338    /**    /**
# Line 598  public final class System Line 347  public final class System
347     */     */
348    public static String getProperty(String key)    public static String getProperty(String key)
349    {    {
350      SecurityManager sm = Runtime.securityManager; // Be thread-safe.      SecurityManager sm = SecurityManager.current; // Be thread-safe.
351      if (sm != null)      if (sm != null)
352        sm.checkPropertyAccess(key);        sm.checkPropertyAccess(key);
353      else if (key.length() == 0)      else if (key.length() == 0)
354        throw new IllegalArgumentException("key can't be empty");        throw new IllegalArgumentException("key can't be empty");
355      return properties.getProperty(key);      return SystemProperties.getProperty(key);
356    }    }
357    
358    /**    /**
# Line 623  public final class System Line 372  public final class System
372      // argument exception.      // argument exception.
373      if (key.equals(""))      if (key.equals(""))
374        throw new IllegalArgumentException("empty key");        throw new IllegalArgumentException("empty key");
375      SecurityManager sm = Runtime.securityManager; // Be thread-safe.      SecurityManager sm = SecurityManager.current; // Be thread-safe.
376      if (sm != null)      if (sm != null)
377        sm.checkPropertyAccess(key);        sm.checkPropertyAccess(key);
378      return properties.getProperty(key, def);      return SystemProperties.getProperty(key, def);
379    }    }
380    
381    /**    /**
# Line 647  public final class System Line 396  public final class System
396      // argument exception.      // argument exception.
397      if (key.equals(""))      if (key.equals(""))
398        throw new IllegalArgumentException("empty key");        throw new IllegalArgumentException("empty key");
399      SecurityManager sm = Runtime.securityManager; // Be thread-safe.      SecurityManager sm = SecurityManager.current; // Be thread-safe.
400      if (sm != null)      if (sm != null)
401        sm.checkPermission(new PropertyPermission(key, "write"));        sm.checkPermission(new PropertyPermission(key, "write"));
402      return (String) properties.setProperty(key, value);      return SystemProperties.setProperty(key, value);
403    }    }
404    
405    /**    /**
# Line 670  public final class System Line 419  public final class System
419      // argument exception.      // argument exception.
420      if (key.equals(""))      if (key.equals(""))
421        throw new IllegalArgumentException("empty key");        throw new IllegalArgumentException("empty key");
422      SecurityManager sm = Runtime.securityManager; // Be thread-safe.      SecurityManager sm = SecurityManager.current; // Be thread-safe.
423      if (sm != null)      if (sm != null)
424        sm.checkPermission(new PropertyPermission(key, "write"));        sm.checkPermission(new PropertyPermission(key, "write"));
425      return (String) properties.remove(key);      return SystemProperties.remove(key);
426    }    }
427    
428    /**    /**
# Line 692  public final class System Line 441  public final class System
441    {    {
442      if (name == null)      if (name == null)
443        throw new NullPointerException();        throw new NullPointerException();
444      SecurityManager sm = Runtime.securityManager; // Be thread-safe.      SecurityManager sm = SecurityManager.current; // Be thread-safe.
445      if (sm != null)      if (sm != null)
446        sm.checkPermission(new RuntimePermission("getenv." + name));        sm.checkPermission(new RuntimePermission("getenv." + name));
447      return VMSystem.getenv(name);      return VMSystem.getenv(name);
# Line 704  public final class System Line 453  public final class System
453     */     */
454    public static Map<String, String> getenv()    public static Map<String, String> getenv()
455    {    {
456      SecurityManager sm = Runtime.securityManager; // Be thread-safe.      SecurityManager sm = SecurityManager.current; // Be thread-safe.
457      if (sm != null)      if (sm != null)
458        sm.checkPermission(new RuntimePermission("getenv.*"));        sm.checkPermission(new RuntimePermission("getenv.*"));
459      return VMSystem.getenv();      return VMSystem.getenv();
# Line 776  public final class System Line 525  public final class System
525     * check may be performed, <code>checkLink</code>. This just calls     * check may be performed, <code>checkLink</code>. This just calls
526     * <code>Runtime.getRuntime().load(filename)</code>.     * <code>Runtime.getRuntime().load(filename)</code>.
527     *     *
528       * <p>
529       * The library is loaded using the class loader associated with the
530       * class associated with the invoking method.
531       *
532     * @param filename the code file to load     * @param filename the code file to load
533     * @throws SecurityException if permission is denied     * @throws SecurityException if permission is denied
534     * @throws UnsatisfiedLinkError if the file cannot be loaded     * @throws UnsatisfiedLinkError if the file cannot be loaded
# Line 783  public final class System Line 536  public final class System
536     */     */
537    public static void load(String filename)    public static void load(String filename)
538    {    {
539      Runtime.getRuntime().load(filename);      Runtime.getRuntime().load(filename, VMStackWalker.getCallingClassLoader());
540    }    }
541    
542    /**    /**
# Line 791  public final class System Line 544  public final class System
544     * check may be performed, <code>checkLink</code>. This just calls     * check may be performed, <code>checkLink</code>. This just calls
545     * <code>Runtime.getRuntime().load(filename)</code>.     * <code>Runtime.getRuntime().load(filename)</code>.
546     *     *
547       * <p>
548       * The library is loaded using the class loader associated with the
549       * class associated with the invoking method.
550       *
551     * @param libname the library file to load     * @param libname the library file to load
552     * @throws SecurityException if permission is denied     * @throws SecurityException if permission is denied
553     * @throws UnsatisfiedLinkError if the file cannot be loaded     * @throws UnsatisfiedLinkError if the file cannot be loaded
# Line 798  public final class System Line 555  public final class System
555     */     */
556    public static void loadLibrary(String libname)    public static void loadLibrary(String libname)
557    {    {
558      Runtime.getRuntime().loadLibrary(libname);      Runtime.getRuntime().loadLibrary(libname,
559          VMStackWalker.getCallingClassLoader());
560    }    }
561    
562    /**    /**
# Line 810  public final class System Line 568  public final class System
568     */     */
569    public static String mapLibraryName(String libname)    public static String mapLibraryName(String libname)
570    {    {
571      // XXX Fix this!!!!      return VMRuntime.mapLibraryName(libname);
     return VMRuntime.nativeGetLibname("", libname);  
572    }    }
573    
574  } // class System  } // class System

Legend:
Removed from v.1.38.2.7  
changed lines
  Added in v.1.38.2.8

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26