src/share/classes/java/lang/System.java

Print this page
rev 10048 : 8044740: Convert all JDK versions used in @since tag to 1.n[.n] in jdk repo
Reviewed-by:


  37 import java.security.AllPermission;
  38 import java.nio.channels.Channel;
  39 import java.nio.channels.spi.SelectorProvider;
  40 import sun.nio.ch.Interruptible;
  41 import sun.reflect.CallerSensitive;
  42 import sun.reflect.Reflection;
  43 import sun.security.util.SecurityConstants;
  44 import sun.reflect.annotation.AnnotationType;
  45 
  46 /**
  47  * The <code>System</code> class contains several useful class fields
  48  * and methods. It cannot be instantiated.
  49  *
  50  * <p>Among the facilities provided by the <code>System</code> class
  51  * are standard input, standard output, and error output streams;
  52  * access to externally defined properties and environment
  53  * variables; a means of loading files and libraries; and a utility
  54  * method for quickly copying a portion of an array.
  55  *
  56  * @author  unascribed
  57  * @since   JDK1.0
  58  */
  59 public final class System {
  60 
  61     /* register the natives via the static initializer.
  62      *
  63      * VM will invoke the initializeSystemClass method to complete
  64      * the initialization for this class separated from clinit.
  65      * Note that to use properties set by the VM, see the constraints
  66      * described in the initializeSystemClass method.
  67      */
  68     private static native void registerNatives();
  69     static {
  70         registerNatives();
  71     }
  72 
  73     /** Don't let anyone instantiate this class */
  74     private System() {
  75     }
  76 
  77     /**


 127      */
 128     private static volatile SecurityManager security = null;
 129 
 130     /**
 131      * Reassigns the "standard" input stream.
 132      *
 133      * <p>First, if there is a security manager, its <code>checkPermission</code>
 134      * method is called with a <code>RuntimePermission("setIO")</code> permission
 135      *  to see if it's ok to reassign the "standard" input stream.
 136      *
 137      * @param in the new standard input stream.
 138      *
 139      * @throws SecurityException
 140      *        if a security manager exists and its
 141      *        <code>checkPermission</code> method doesn't allow
 142      *        reassigning of the standard input stream.
 143      *
 144      * @see SecurityManager#checkPermission
 145      * @see java.lang.RuntimePermission
 146      *
 147      * @since   JDK1.1
 148      */
 149     public static void setIn(InputStream in) {
 150         checkIO();
 151         setIn0(in);
 152     }
 153 
 154     /**
 155      * Reassigns the "standard" output stream.
 156      *
 157      * <p>First, if there is a security manager, its <code>checkPermission</code>
 158      * method is called with a <code>RuntimePermission("setIO")</code> permission
 159      *  to see if it's ok to reassign the "standard" output stream.
 160      *
 161      * @param out the new standard output stream
 162      *
 163      * @throws SecurityException
 164      *        if a security manager exists and its
 165      *        <code>checkPermission</code> method doesn't allow
 166      *        reassigning of the standard output stream.
 167      *
 168      * @see SecurityManager#checkPermission
 169      * @see java.lang.RuntimePermission
 170      *
 171      * @since   JDK1.1
 172      */
 173     public static void setOut(PrintStream out) {
 174         checkIO();
 175         setOut0(out);
 176     }
 177 
 178     /**
 179      * Reassigns the "standard" error output stream.
 180      *
 181      * <p>First, if there is a security manager, its <code>checkPermission</code>
 182      * method is called with a <code>RuntimePermission("setIO")</code> permission
 183      *  to see if it's ok to reassign the "standard" error output stream.
 184      *
 185      * @param err the new standard error output stream.
 186      *
 187      * @throws SecurityException
 188      *        if a security manager exists and its
 189      *        <code>checkPermission</code> method doesn't allow
 190      *        reassigning of the standard error output stream.
 191      *
 192      * @see SecurityManager#checkPermission
 193      * @see java.lang.RuntimePermission
 194      *
 195      * @since   JDK1.1
 196      */
 197     public static void setErr(PrintStream err) {
 198         checkIO();
 199         setErr0(err);
 200     }
 201 
 202     private static volatile Console cons = null;
 203     /**
 204      * Returns the unique {@link java.io.Console Console} object associated
 205      * with the current Java virtual machine, if any.
 206      *
 207      * @return  The system console, if any, otherwise <tt>null</tt>.
 208      *
 209      * @since   1.6
 210      */
 211      public static Console console() {
 212          if (cons == null) {
 213              synchronized (System.class) {
 214                  cons = sun.misc.SharedSecrets.getJavaIOAccess().console();
 215              }


 485      *               access of data outside array bounds.
 486      * @exception  ArrayStoreException  if an element in the <code>src</code>
 487      *               array could not be stored into the <code>dest</code> array
 488      *               because of a type mismatch.
 489      * @exception  NullPointerException if either <code>src</code> or
 490      *               <code>dest</code> is <code>null</code>.
 491      */
 492     public static native void arraycopy(Object src,  int  srcPos,
 493                                         Object dest, int destPos,
 494                                         int length);
 495 
 496     /**
 497      * Returns the same hash code for the given object as
 498      * would be returned by the default method hashCode(),
 499      * whether or not the given object's class overrides
 500      * hashCode().
 501      * The hash code for the null reference is zero.
 502      *
 503      * @param x object for which the hashCode is to be calculated
 504      * @return  the hashCode
 505      * @since   JDK1.1
 506      */
 507     public static native int identityHashCode(Object x);
 508 
 509     /**
 510      * System properties. The following properties are guaranteed to be defined:
 511      * <dl>
 512      * <dt>java.version         <dd>Java version number
 513      * <dt>java.vendor          <dd>Java vendor specific string
 514      * <dt>java.vendor.url      <dd>Java vendor URL
 515      * <dt>java.home            <dd>Java installation directory
 516      * <dt>java.class.version   <dd>Java class version number
 517      * <dt>java.class.path      <dd>Java classpath
 518      * <dt>os.name              <dd>Operating System Name
 519      * <dt>os.arch              <dd>Operating System Architecture
 520      * <dt>os.version           <dd>Operating System Version
 521      * <dt>file.separator       <dd>File separator ("/" on Unix)
 522      * <dt>path.separator       <dd>Path separator (":" on Unix)
 523      * <dt>line.separator       <dd>Line separator ("\n" on Unix)
 524      * <dt>user.name            <dd>User account name
 525      * <dt>user.home            <dd>User home directory


1015      * automatically invoked are to be run before the Java runtime exits.
1016      * By default, finalization on exit is disabled.
1017      *
1018      * <p>If there is a security manager,
1019      * its <code>checkExit</code> method is first called
1020      * with 0 as its argument to ensure the exit is allowed.
1021      * This could result in a SecurityException.
1022      *
1023      * @deprecated  This method is inherently unsafe.  It may result in
1024      *      finalizers being called on live objects while other threads are
1025      *      concurrently manipulating those objects, resulting in erratic
1026      *      behavior or deadlock.
1027      * @param value indicating enabling or disabling of finalization
1028      * @throws  SecurityException
1029      *        if a security manager exists and its <code>checkExit</code>
1030      *        method doesn't allow the exit.
1031      *
1032      * @see     java.lang.Runtime#exit(int)
1033      * @see     java.lang.Runtime#gc()
1034      * @see     java.lang.SecurityManager#checkExit(int)
1035      * @since   JDK1.1
1036      */
1037     @Deprecated
1038     public static void runFinalizersOnExit(boolean value) {
1039         Runtime.runFinalizersOnExit(value);
1040     }
1041 
1042     /**
1043      * Loads the native library specified by the filename argument.  The filename
1044      * argument must be an absolute path name.
1045      *
1046      * If the filename argument, when stripped of any platform-specific library
1047      * prefix, path, and file extension, indicates a library whose name is,
1048      * for example, L, and a native library called L is statically linked
1049      * with the VM, then the JNI_OnLoad_L function exported by the library
1050      * is invoked rather than attempting to load a dynamic library.
1051      * A filename matching the argument does not have to exist in the
1052      * file system.
1053      * See the JNI Specification for more details.
1054      *
1055      * Otherwise, the filename argument is mapped to a native library image in




  37 import java.security.AllPermission;
  38 import java.nio.channels.Channel;
  39 import java.nio.channels.spi.SelectorProvider;
  40 import sun.nio.ch.Interruptible;
  41 import sun.reflect.CallerSensitive;
  42 import sun.reflect.Reflection;
  43 import sun.security.util.SecurityConstants;
  44 import sun.reflect.annotation.AnnotationType;
  45 
  46 /**
  47  * The <code>System</code> class contains several useful class fields
  48  * and methods. It cannot be instantiated.
  49  *
  50  * <p>Among the facilities provided by the <code>System</code> class
  51  * are standard input, standard output, and error output streams;
  52  * access to externally defined properties and environment
  53  * variables; a means of loading files and libraries; and a utility
  54  * method for quickly copying a portion of an array.
  55  *
  56  * @author  unascribed
  57  * @since   1.0
  58  */
  59 public final class System {
  60 
  61     /* register the natives via the static initializer.
  62      *
  63      * VM will invoke the initializeSystemClass method to complete
  64      * the initialization for this class separated from clinit.
  65      * Note that to use properties set by the VM, see the constraints
  66      * described in the initializeSystemClass method.
  67      */
  68     private static native void registerNatives();
  69     static {
  70         registerNatives();
  71     }
  72 
  73     /** Don't let anyone instantiate this class */
  74     private System() {
  75     }
  76 
  77     /**


 127      */
 128     private static volatile SecurityManager security = null;
 129 
 130     /**
 131      * Reassigns the "standard" input stream.
 132      *
 133      * <p>First, if there is a security manager, its <code>checkPermission</code>
 134      * method is called with a <code>RuntimePermission("setIO")</code> permission
 135      *  to see if it's ok to reassign the "standard" input stream.
 136      *
 137      * @param in the new standard input stream.
 138      *
 139      * @throws SecurityException
 140      *        if a security manager exists and its
 141      *        <code>checkPermission</code> method doesn't allow
 142      *        reassigning of the standard input stream.
 143      *
 144      * @see SecurityManager#checkPermission
 145      * @see java.lang.RuntimePermission
 146      *
 147      * @since   1.1
 148      */
 149     public static void setIn(InputStream in) {
 150         checkIO();
 151         setIn0(in);
 152     }
 153 
 154     /**
 155      * Reassigns the "standard" output stream.
 156      *
 157      * <p>First, if there is a security manager, its <code>checkPermission</code>
 158      * method is called with a <code>RuntimePermission("setIO")</code> permission
 159      *  to see if it's ok to reassign the "standard" output stream.
 160      *
 161      * @param out the new standard output stream
 162      *
 163      * @throws SecurityException
 164      *        if a security manager exists and its
 165      *        <code>checkPermission</code> method doesn't allow
 166      *        reassigning of the standard output stream.
 167      *
 168      * @see SecurityManager#checkPermission
 169      * @see java.lang.RuntimePermission
 170      *
 171      * @since   1.1
 172      */
 173     public static void setOut(PrintStream out) {
 174         checkIO();
 175         setOut0(out);
 176     }
 177 
 178     /**
 179      * Reassigns the "standard" error output stream.
 180      *
 181      * <p>First, if there is a security manager, its <code>checkPermission</code>
 182      * method is called with a <code>RuntimePermission("setIO")</code> permission
 183      *  to see if it's ok to reassign the "standard" error output stream.
 184      *
 185      * @param err the new standard error output stream.
 186      *
 187      * @throws SecurityException
 188      *        if a security manager exists and its
 189      *        <code>checkPermission</code> method doesn't allow
 190      *        reassigning of the standard error output stream.
 191      *
 192      * @see SecurityManager#checkPermission
 193      * @see java.lang.RuntimePermission
 194      *
 195      * @since   1.1
 196      */
 197     public static void setErr(PrintStream err) {
 198         checkIO();
 199         setErr0(err);
 200     }
 201 
 202     private static volatile Console cons = null;
 203     /**
 204      * Returns the unique {@link java.io.Console Console} object associated
 205      * with the current Java virtual machine, if any.
 206      *
 207      * @return  The system console, if any, otherwise <tt>null</tt>.
 208      *
 209      * @since   1.6
 210      */
 211      public static Console console() {
 212          if (cons == null) {
 213              synchronized (System.class) {
 214                  cons = sun.misc.SharedSecrets.getJavaIOAccess().console();
 215              }


 485      *               access of data outside array bounds.
 486      * @exception  ArrayStoreException  if an element in the <code>src</code>
 487      *               array could not be stored into the <code>dest</code> array
 488      *               because of a type mismatch.
 489      * @exception  NullPointerException if either <code>src</code> or
 490      *               <code>dest</code> is <code>null</code>.
 491      */
 492     public static native void arraycopy(Object src,  int  srcPos,
 493                                         Object dest, int destPos,
 494                                         int length);
 495 
 496     /**
 497      * Returns the same hash code for the given object as
 498      * would be returned by the default method hashCode(),
 499      * whether or not the given object's class overrides
 500      * hashCode().
 501      * The hash code for the null reference is zero.
 502      *
 503      * @param x object for which the hashCode is to be calculated
 504      * @return  the hashCode
 505      * @since   1.1
 506      */
 507     public static native int identityHashCode(Object x);
 508 
 509     /**
 510      * System properties. The following properties are guaranteed to be defined:
 511      * <dl>
 512      * <dt>java.version         <dd>Java version number
 513      * <dt>java.vendor          <dd>Java vendor specific string
 514      * <dt>java.vendor.url      <dd>Java vendor URL
 515      * <dt>java.home            <dd>Java installation directory
 516      * <dt>java.class.version   <dd>Java class version number
 517      * <dt>java.class.path      <dd>Java classpath
 518      * <dt>os.name              <dd>Operating System Name
 519      * <dt>os.arch              <dd>Operating System Architecture
 520      * <dt>os.version           <dd>Operating System Version
 521      * <dt>file.separator       <dd>File separator ("/" on Unix)
 522      * <dt>path.separator       <dd>Path separator (":" on Unix)
 523      * <dt>line.separator       <dd>Line separator ("\n" on Unix)
 524      * <dt>user.name            <dd>User account name
 525      * <dt>user.home            <dd>User home directory


1015      * automatically invoked are to be run before the Java runtime exits.
1016      * By default, finalization on exit is disabled.
1017      *
1018      * <p>If there is a security manager,
1019      * its <code>checkExit</code> method is first called
1020      * with 0 as its argument to ensure the exit is allowed.
1021      * This could result in a SecurityException.
1022      *
1023      * @deprecated  This method is inherently unsafe.  It may result in
1024      *      finalizers being called on live objects while other threads are
1025      *      concurrently manipulating those objects, resulting in erratic
1026      *      behavior or deadlock.
1027      * @param value indicating enabling or disabling of finalization
1028      * @throws  SecurityException
1029      *        if a security manager exists and its <code>checkExit</code>
1030      *        method doesn't allow the exit.
1031      *
1032      * @see     java.lang.Runtime#exit(int)
1033      * @see     java.lang.Runtime#gc()
1034      * @see     java.lang.SecurityManager#checkExit(int)
1035      * @since   1.1
1036      */
1037     @Deprecated
1038     public static void runFinalizersOnExit(boolean value) {
1039         Runtime.runFinalizersOnExit(value);
1040     }
1041 
1042     /**
1043      * Loads the native library specified by the filename argument.  The filename
1044      * argument must be an absolute path name.
1045      *
1046      * If the filename argument, when stripped of any platform-specific library
1047      * prefix, path, and file extension, indicates a library whose name is,
1048      * for example, L, and a native library called L is statically linked
1049      * with the VM, then the JNI_OnLoad_L function exported by the library
1050      * is invoked rather than attempting to load a dynamic library.
1051      * A filename matching the argument does not have to exist in the
1052      * file system.
1053      * See the JNI Specification for more details.
1054      *
1055      * Otherwise, the filename argument is mapped to a native library image in