1 /*
   2  * Copyright (c) 1994, 2016, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 package java.lang;
  26 
  27 import java.io.*;
  28 import java.lang.reflect.Executable;
  29 import java.lang.annotation.Annotation;
  30 import java.security.AccessControlContext;
  31 import java.util.Properties;
  32 import java.util.PropertyPermission;
  33 import java.util.Map;
  34 import java.security.AccessController;
  35 import java.security.PrivilegedAction;
  36 import java.nio.channels.Channel;
  37 import java.nio.channels.spi.SelectorProvider;
  38 import java.util.Objects;
  39 import java.util.ResourceBundle;
  40 import java.util.function.Supplier;
  41 import sun.nio.ch.Interruptible;
  42 import sun.reflect.CallerSensitive;
  43 import sun.reflect.Reflection;
  44 import sun.security.util.SecurityConstants;
  45 import sun.reflect.annotation.AnnotationType;
  46 import jdk.internal.HotSpotIntrinsicCandidate;
  47 import jdk.internal.misc.JavaLangAccess;;
  48 import jdk.internal.misc.SharedSecrets;;
  49 import jdk.internal.misc.VM;
  50 import jdk.internal.logger.LoggerFinderLoader;
  51 import jdk.internal.logger.LazyLoggers;
  52 import jdk.internal.logger.LocalizedLoggerWrapper;
  53 
  54 /**
  55  * The <code>System</code> class contains several useful class fields
  56  * and methods. It cannot be instantiated.
  57  *
  58  * <p>Among the facilities provided by the <code>System</code> class
  59  * are standard input, standard output, and error output streams;
  60  * access to externally defined properties and environment
  61  * variables; a means of loading files and libraries; and a utility
  62  * method for quickly copying a portion of an array.
  63  *
  64  * @author  unascribed
  65  * @since   1.0
  66  */
  67 public final class System {
  68 
  69     /* register the natives via the static initializer.
  70      *
  71      * VM will invoke the initializeSystemClass method to complete
  72      * the initialization for this class separated from clinit.
  73      * Note that to use properties set by the VM, see the constraints
  74      * described in the initializeSystemClass method.
  75      */
  76     private static native void registerNatives();
  77     static {
  78         registerNatives();
  79     }
  80 
  81     /** Don't let anyone instantiate this class */
  82     private System() {
  83     }
  84 
  85     /**
  86      * The "standard" input stream. This stream is already
  87      * open and ready to supply input data. Typically this stream
  88      * corresponds to keyboard input or another input source specified by
  89      * the host environment or user.
  90      */
  91     public static final InputStream in = null;
  92 
  93     /**
  94      * The "standard" output stream. This stream is already
  95      * open and ready to accept output data. Typically this stream
  96      * corresponds to display output or another output destination
  97      * specified by the host environment or user.
  98      * <p>
  99      * For simple stand-alone Java applications, a typical way to write
 100      * a line of output data is:
 101      * <blockquote><pre>
 102      *     System.out.println(data)
 103      * </pre></blockquote>
 104      * <p>
 105      * See the <code>println</code> methods in class <code>PrintStream</code>.
 106      *
 107      * @see     java.io.PrintStream#println()
 108      * @see     java.io.PrintStream#println(boolean)
 109      * @see     java.io.PrintStream#println(char)
 110      * @see     java.io.PrintStream#println(char[])
 111      * @see     java.io.PrintStream#println(double)
 112      * @see     java.io.PrintStream#println(float)
 113      * @see     java.io.PrintStream#println(int)
 114      * @see     java.io.PrintStream#println(long)
 115      * @see     java.io.PrintStream#println(java.lang.Object)
 116      * @see     java.io.PrintStream#println(java.lang.String)
 117      */
 118     public static final PrintStream out = null;
 119 
 120     /**
 121      * The "standard" error output stream. This stream is already
 122      * open and ready to accept output data.
 123      * <p>
 124      * Typically this stream corresponds to display output or another
 125      * output destination specified by the host environment or user. By
 126      * convention, this output stream is used to display error messages
 127      * or other information that should come to the immediate attention
 128      * of a user even if the principal output stream, the value of the
 129      * variable <code>out</code>, has been redirected to a file or other
 130      * destination that is typically not continuously monitored.
 131      */
 132     public static final PrintStream err = null;
 133 
 134     /* The security manager for the system.
 135      */
 136     private static volatile SecurityManager security;
 137 
 138     /**
 139      * Reassigns the "standard" input stream.
 140      *
 141      * <p>First, if there is a security manager, its <code>checkPermission</code>
 142      * method is called with a <code>RuntimePermission("setIO")</code> permission
 143      *  to see if it's ok to reassign the "standard" input stream.
 144      *
 145      * @param in the new standard input stream.
 146      *
 147      * @throws SecurityException
 148      *        if a security manager exists and its
 149      *        <code>checkPermission</code> method doesn't allow
 150      *        reassigning of the standard input stream.
 151      *
 152      * @see SecurityManager#checkPermission
 153      * @see java.lang.RuntimePermission
 154      *
 155      * @since   1.1
 156      */
 157     public static void setIn(InputStream in) {
 158         checkIO();
 159         setIn0(in);
 160     }
 161 
 162     /**
 163      * Reassigns the "standard" output stream.
 164      *
 165      * <p>First, if there is a security manager, its <code>checkPermission</code>
 166      * method is called with a <code>RuntimePermission("setIO")</code> permission
 167      *  to see if it's ok to reassign the "standard" output stream.
 168      *
 169      * @param out the new standard output stream
 170      *
 171      * @throws SecurityException
 172      *        if a security manager exists and its
 173      *        <code>checkPermission</code> method doesn't allow
 174      *        reassigning of the standard output stream.
 175      *
 176      * @see SecurityManager#checkPermission
 177      * @see java.lang.RuntimePermission
 178      *
 179      * @since   1.1
 180      */
 181     public static void setOut(PrintStream out) {
 182         checkIO();
 183         setOut0(out);
 184     }
 185 
 186     /**
 187      * Reassigns the "standard" error output stream.
 188      *
 189      * <p>First, if there is a security manager, its <code>checkPermission</code>
 190      * method is called with a <code>RuntimePermission("setIO")</code> permission
 191      *  to see if it's ok to reassign the "standard" error output stream.
 192      *
 193      * @param err the new standard error output stream.
 194      *
 195      * @throws SecurityException
 196      *        if a security manager exists and its
 197      *        <code>checkPermission</code> method doesn't allow
 198      *        reassigning of the standard error output stream.
 199      *
 200      * @see SecurityManager#checkPermission
 201      * @see java.lang.RuntimePermission
 202      *
 203      * @since   1.1
 204      */
 205     public static void setErr(PrintStream err) {
 206         checkIO();
 207         setErr0(err);
 208     }
 209 
 210     private static volatile Console cons;
 211     /**
 212      * Returns the unique {@link java.io.Console Console} object associated
 213      * with the current Java virtual machine, if any.
 214      *
 215      * @return  The system console, if any, otherwise {@code null}.
 216      *
 217      * @since   1.6
 218      */
 219      public static Console console() {
 220          Console c = cons;
 221          if (c == null) {
 222              synchronized (System.class) {
 223                  cons = c = SharedSecrets.getJavaIOAccess().console();
 224              }
 225          }
 226          return c;
 227      }
 228 
 229     /**
 230      * Returns the channel inherited from the entity that created this
 231      * Java virtual machine.
 232      *
 233      * <p> This method returns the channel obtained by invoking the
 234      * {@link java.nio.channels.spi.SelectorProvider#inheritedChannel
 235      * inheritedChannel} method of the system-wide default
 236      * {@link java.nio.channels.spi.SelectorProvider} object. </p>
 237      *
 238      * <p> In addition to the network-oriented channels described in
 239      * {@link java.nio.channels.spi.SelectorProvider#inheritedChannel
 240      * inheritedChannel}, this method may return other kinds of
 241      * channels in the future.
 242      *
 243      * @return  The inherited channel, if any, otherwise {@code null}.
 244      *
 245      * @throws  IOException
 246      *          If an I/O error occurs
 247      *
 248      * @throws  SecurityException
 249      *          If a security manager is present and it does not
 250      *          permit access to the channel.
 251      *
 252      * @since 1.5
 253      */
 254     public static Channel inheritedChannel() throws IOException {
 255         return SelectorProvider.provider().inheritedChannel();
 256     }
 257 
 258     private static void checkIO() {
 259         SecurityManager sm = getSecurityManager();
 260         if (sm != null) {
 261             sm.checkPermission(new RuntimePermission("setIO"));
 262         }
 263     }
 264 
 265     private static native void setIn0(InputStream in);
 266     private static native void setOut0(PrintStream out);
 267     private static native void setErr0(PrintStream err);
 268 
 269     /**
 270      * Sets the System security.
 271      *
 272      * <p> If there is a security manager already installed, this method first
 273      * calls the security manager's <code>checkPermission</code> method
 274      * with a <code>RuntimePermission("setSecurityManager")</code>
 275      * permission to ensure it's ok to replace the existing
 276      * security manager.
 277      * This may result in throwing a <code>SecurityException</code>.
 278      *
 279      * <p> Otherwise, the argument is established as the current
 280      * security manager. If the argument is <code>null</code> and no
 281      * security manager has been established, then no action is taken and
 282      * the method simply returns.
 283      *
 284      * @param      s   the security manager.
 285      * @exception  SecurityException  if the security manager has already
 286      *             been set and its <code>checkPermission</code> method
 287      *             doesn't allow it to be replaced.
 288      * @see #getSecurityManager
 289      * @see SecurityManager#checkPermission
 290      * @see java.lang.RuntimePermission
 291      */
 292     public static
 293     void setSecurityManager(final SecurityManager s) {
 294         try {
 295             s.checkPackageAccess("java.lang");
 296         } catch (Exception e) {
 297             // no-op
 298         }
 299         setSecurityManager0(s);
 300     }
 301 
 302     private static synchronized
 303     void setSecurityManager0(final SecurityManager s) {
 304         SecurityManager sm = getSecurityManager();
 305         if (sm != null) {
 306             // ask the currently installed security manager if we
 307             // can replace it.
 308             sm.checkPermission(new RuntimePermission
 309                                      ("setSecurityManager"));
 310         }
 311 
 312         if ((s != null) && (s.getClass().getClassLoader() != null)) {
 313             // New security manager class is not on bootstrap classpath.
 314             // Cause policy to get initialized before we install the new
 315             // security manager, in order to prevent infinite loops when
 316             // trying to initialize the policy (which usually involves
 317             // accessing some security and/or system properties, which in turn
 318             // calls the installed security manager's checkPermission method
 319             // which will loop infinitely if there is a non-system class
 320             // (in this case: the new security manager class) on the stack).
 321             AccessController.doPrivileged(new PrivilegedAction<>() {
 322                 public Object run() {
 323                     s.getClass().getProtectionDomain().implies
 324                         (SecurityConstants.ALL_PERMISSION);
 325                     return null;
 326                 }
 327             });
 328         }
 329 
 330         security = s;
 331     }
 332 
 333     /**
 334      * Gets the system security interface.
 335      *
 336      * @return  if a security manager has already been established for the
 337      *          current application, then that security manager is returned;
 338      *          otherwise, <code>null</code> is returned.
 339      * @see     #setSecurityManager
 340      */
 341     public static SecurityManager getSecurityManager() {
 342         return security;
 343     }
 344 
 345     /**
 346      * Returns the current time in milliseconds.  Note that
 347      * while the unit of time of the return value is a millisecond,
 348      * the granularity of the value depends on the underlying
 349      * operating system and may be larger.  For example, many
 350      * operating systems measure time in units of tens of
 351      * milliseconds.
 352      *
 353      * <p> See the description of the class <code>Date</code> for
 354      * a discussion of slight discrepancies that may arise between
 355      * "computer time" and coordinated universal time (UTC).
 356      *
 357      * @return  the difference, measured in milliseconds, between
 358      *          the current time and midnight, January 1, 1970 UTC.
 359      * @see     java.util.Date
 360      */
 361     @HotSpotIntrinsicCandidate
 362     public static native long currentTimeMillis();
 363 
 364     /**
 365      * Returns the current value of the running Java Virtual Machine's
 366      * high-resolution time source, in nanoseconds.
 367      *
 368      * <p>This method can only be used to measure elapsed time and is
 369      * not related to any other notion of system or wall-clock time.
 370      * The value returned represents nanoseconds since some fixed but
 371      * arbitrary <i>origin</i> time (perhaps in the future, so values
 372      * may be negative).  The same origin is used by all invocations of
 373      * this method in an instance of a Java virtual machine; other
 374      * virtual machine instances are likely to use a different origin.
 375      *
 376      * <p>This method provides nanosecond precision, but not necessarily
 377      * nanosecond resolution (that is, how frequently the value changes)
 378      * - no guarantees are made except that the resolution is at least as
 379      * good as that of {@link #currentTimeMillis()}.
 380      *
 381      * <p>Differences in successive calls that span greater than
 382      * approximately 292 years (2<sup>63</sup> nanoseconds) will not
 383      * correctly compute elapsed time due to numerical overflow.
 384      *
 385      * <p>The values returned by this method become meaningful only when
 386      * the difference between two such values, obtained within the same
 387      * instance of a Java virtual machine, is computed.
 388      *
 389      * <p>For example, to measure how long some code takes to execute:
 390      * <pre> {@code
 391      * long startTime = System.nanoTime();
 392      * // ... the code being measured ...
 393      * long elapsedNanos = System.nanoTime() - startTime;}</pre>
 394      *
 395      * <p>To compare elapsed time against a timeout, use <pre> {@code
 396      * if (System.nanoTime() - startTime >= timeoutNanos) ...}</pre>
 397      * instead of <pre> {@code
 398      * if (System.nanoTime() >= startTime + timeoutNanos) ...}</pre>
 399      * because of the possibility of numerical overflow.
 400      *
 401      * @return the current value of the running Java Virtual Machine's
 402      *         high-resolution time source, in nanoseconds
 403      * @since 1.5
 404      */
 405     @HotSpotIntrinsicCandidate
 406     public static native long nanoTime();
 407 
 408     /**
 409      * Copies an array from the specified source array, beginning at the
 410      * specified position, to the specified position of the destination array.
 411      * A subsequence of array components are copied from the source
 412      * array referenced by <code>src</code> to the destination array
 413      * referenced by <code>dest</code>. The number of components copied is
 414      * equal to the <code>length</code> argument. The components at
 415      * positions <code>srcPos</code> through
 416      * <code>srcPos+length-1</code> in the source array are copied into
 417      * positions <code>destPos</code> through
 418      * <code>destPos+length-1</code>, respectively, of the destination
 419      * array.
 420      * <p>
 421      * If the <code>src</code> and <code>dest</code> arguments refer to the
 422      * same array object, then the copying is performed as if the
 423      * components at positions <code>srcPos</code> through
 424      * <code>srcPos+length-1</code> were first copied to a temporary
 425      * array with <code>length</code> components and then the contents of
 426      * the temporary array were copied into positions
 427      * <code>destPos</code> through <code>destPos+length-1</code> of the
 428      * destination array.
 429      * <p>
 430      * If <code>dest</code> is <code>null</code>, then a
 431      * <code>NullPointerException</code> is thrown.
 432      * <p>
 433      * If <code>src</code> is <code>null</code>, then a
 434      * <code>NullPointerException</code> is thrown and the destination
 435      * array is not modified.
 436      * <p>
 437      * Otherwise, if any of the following is true, an
 438      * <code>ArrayStoreException</code> is thrown and the destination is
 439      * not modified:
 440      * <ul>
 441      * <li>The <code>src</code> argument refers to an object that is not an
 442      *     array.
 443      * <li>The <code>dest</code> argument refers to an object that is not an
 444      *     array.
 445      * <li>The <code>src</code> argument and <code>dest</code> argument refer
 446      *     to arrays whose component types are different primitive types.
 447      * <li>The <code>src</code> argument refers to an array with a primitive
 448      *    component type and the <code>dest</code> argument refers to an array
 449      *     with a reference component type.
 450      * <li>The <code>src</code> argument refers to an array with a reference
 451      *    component type and the <code>dest</code> argument refers to an array
 452      *     with a primitive component type.
 453      * </ul>
 454      * <p>
 455      * Otherwise, if any of the following is true, an
 456      * <code>IndexOutOfBoundsException</code> is
 457      * thrown and the destination is not modified:
 458      * <ul>
 459      * <li>The <code>srcPos</code> argument is negative.
 460      * <li>The <code>destPos</code> argument is negative.
 461      * <li>The <code>length</code> argument is negative.
 462      * <li><code>srcPos+length</code> is greater than
 463      *     <code>src.length</code>, the length of the source array.
 464      * <li><code>destPos+length</code> is greater than
 465      *     <code>dest.length</code>, the length of the destination array.
 466      * </ul>
 467      * <p>
 468      * Otherwise, if any actual component of the source array from
 469      * position <code>srcPos</code> through
 470      * <code>srcPos+length-1</code> cannot be converted to the component
 471      * type of the destination array by assignment conversion, an
 472      * <code>ArrayStoreException</code> is thrown. In this case, let
 473      * <b><i>k</i></b> be the smallest nonnegative integer less than
 474      * length such that <code>src[srcPos+</code><i>k</i><code>]</code>
 475      * cannot be converted to the component type of the destination
 476      * array; when the exception is thrown, source array components from
 477      * positions <code>srcPos</code> through
 478      * <code>srcPos+</code><i>k</i><code>-1</code>
 479      * will already have been copied to destination array positions
 480      * <code>destPos</code> through
 481      * <code>destPos+</code><i>k</I><code>-1</code> and no other
 482      * positions of the destination array will have been modified.
 483      * (Because of the restrictions already itemized, this
 484      * paragraph effectively applies only to the situation where both
 485      * arrays have component types that are reference types.)
 486      *
 487      * @param      src      the source array.
 488      * @param      srcPos   starting position in the source array.
 489      * @param      dest     the destination array.
 490      * @param      destPos  starting position in the destination data.
 491      * @param      length   the number of array elements to be copied.
 492      * @exception  IndexOutOfBoundsException  if copying would cause
 493      *               access of data outside array bounds.
 494      * @exception  ArrayStoreException  if an element in the <code>src</code>
 495      *               array could not be stored into the <code>dest</code> array
 496      *               because of a type mismatch.
 497      * @exception  NullPointerException if either <code>src</code> or
 498      *               <code>dest</code> is <code>null</code>.
 499      */
 500     @HotSpotIntrinsicCandidate
 501     public static native void arraycopy(Object src,  int  srcPos,
 502                                         Object dest, int destPos,
 503                                         int length);
 504 
 505     /**
 506      * Returns the same hash code for the given object as
 507      * would be returned by the default method hashCode(),
 508      * whether or not the given object's class overrides
 509      * hashCode().
 510      * The hash code for the null reference is zero.
 511      *
 512      * @param x object for which the hashCode is to be calculated
 513      * @return  the hashCode
 514      * @since   1.1
 515      */
 516     @HotSpotIntrinsicCandidate
 517     public static native int identityHashCode(Object x);
 518 
 519     /**
 520      * System properties. The following properties are guaranteed to be defined:
 521      * <dl>
 522      * <dt>java.version         <dd>Java version number
 523      * <dt>java.vendor          <dd>Java vendor specific string
 524      * <dt>java.vendor.url      <dd>Java vendor URL
 525      * <dt>java.home            <dd>Java installation directory
 526      * <dt>java.class.version   <dd>Java class version number
 527      * <dt>java.class.path      <dd>Java classpath
 528      * <dt>os.name              <dd>Operating System Name
 529      * <dt>os.arch              <dd>Operating System Architecture
 530      * <dt>os.version           <dd>Operating System Version
 531      * <dt>file.separator       <dd>File separator ("/" on Unix)
 532      * <dt>path.separator       <dd>Path separator (":" on Unix)
 533      * <dt>line.separator       <dd>Line separator ("\n" on Unix)
 534      * <dt>user.name            <dd>User account name
 535      * <dt>user.home            <dd>User home directory
 536      * <dt>user.dir             <dd>User's current working directory
 537      * </dl>
 538      */
 539 
 540     private static Properties props;
 541     private static native Properties initProperties(Properties props);
 542 
 543     /**
 544      * Determines the current system properties.
 545      * <p>
 546      * First, if there is a security manager, its
 547      * <code>checkPropertiesAccess</code> method is called with no
 548      * arguments. This may result in a security exception.
 549      * <p>
 550      * The current set of system properties for use by the
 551      * {@link #getProperty(String)} method is returned as a
 552      * <code>Properties</code> object. If there is no current set of
 553      * system properties, a set of system properties is first created and
 554      * initialized. This set of system properties always includes values
 555      * for the following keys:
 556      * <table summary="Shows property keys and associated values">
 557      * <tr><th>Key</th>
 558      *     <th>Description of Associated Value</th></tr>
 559      * <tr><td><code>java.version</code></td>
 560      *     <td>Java Runtime Environment version which may be interpreted
 561      *     as a {@link Runtime.Version}</td></tr>
 562      * <tr><td><code>java.vendor</code></td>
 563      *     <td>Java Runtime Environment vendor</td></tr>
 564      * <tr><td><code>java.vendor.url</code></td>
 565      *     <td>Java vendor URL</td></tr>
 566      * <tr><td><code>java.home</code></td>
 567      *     <td>Java installation directory</td></tr>
 568      * <tr><td><code>java.vm.specification.version</code></td>
 569      *     <td>Java Virtual Machine specification version which may be
 570      *     interpreted as a {@link Runtime.Version}</td></tr>
 571      * <tr><td><code>java.vm.specification.vendor</code></td>
 572      *     <td>Java Virtual Machine specification vendor</td></tr>
 573      * <tr><td><code>java.vm.specification.name</code></td>
 574      *     <td>Java Virtual Machine specification name</td></tr>
 575      * <tr><td><code>java.vm.version</code></td>
 576      *     <td>Java Virtual Machine implementation version which may be
 577      *     interpreted as a {@link Runtime.Version} </td></tr>
 578      * <tr><td><code>java.vm.vendor</code></td>
 579      *     <td>Java Virtual Machine implementation vendor</td></tr>
 580      * <tr><td><code>java.vm.name</code></td>
 581      *     <td>Java Virtual Machine implementation name</td></tr>
 582      * <tr><td><code>java.specification.version</code></td>
 583      *     <td>Java Runtime Environment specification  version which may
 584      *     be interpreted as a {@link Runtime.Version} </td></tr>
 585      * <tr><td><code>java.specification.vendor</code></td>
 586      *     <td>Java Runtime Environment specification  vendor</td></tr>
 587      * <tr><td><code>java.specification.name</code></td>
 588      *     <td>Java Runtime Environment specification  name</td></tr>
 589      * <tr><td><code>java.class.version</code></td>
 590      *     <td>Java class format version number</td></tr>
 591      * <tr><td><code>java.class.path</code></td>
 592      *     <td>Java class path</td></tr>
 593      * <tr><td><code>java.library.path</code></td>
 594      *     <td>List of paths to search when loading libraries</td></tr>
 595      * <tr><td><code>java.io.tmpdir</code></td>
 596      *     <td>Default temp file path</td></tr>
 597      * <tr><td><code>java.compiler</code></td>
 598      *     <td>Name of JIT compiler to use</td></tr>
 599      * <tr><td><code>os.name</code></td>
 600      *     <td>Operating system name</td></tr>
 601      * <tr><td><code>os.arch</code></td>
 602      *     <td>Operating system architecture</td></tr>
 603      * <tr><td><code>os.version</code></td>
 604      *     <td>Operating system version</td></tr>
 605      * <tr><td><code>file.separator</code></td>
 606      *     <td>File separator ("/" on UNIX)</td></tr>
 607      * <tr><td><code>path.separator</code></td>
 608      *     <td>Path separator (":" on UNIX)</td></tr>
 609      * <tr><td><code>line.separator</code></td>
 610      *     <td>Line separator ("\n" on UNIX)</td></tr>
 611      * <tr><td><code>user.name</code></td>
 612      *     <td>User's account name</td></tr>
 613      * <tr><td><code>user.home</code></td>
 614      *     <td>User's home directory</td></tr>
 615      * <tr><td><code>user.dir</code></td>
 616      *     <td>User's current working directory</td></tr>
 617      * </table>
 618      * <p>
 619      * Multiple paths in a system property value are separated by the path
 620      * separator character of the platform.
 621      * <p>
 622      * Note that even if the security manager does not permit the
 623      * <code>getProperties</code> operation, it may choose to permit the
 624      * {@link #getProperty(String)} operation.
 625      *
 626      * @return     the system properties
 627      * @exception  SecurityException  if a security manager exists and its
 628      *             <code>checkPropertiesAccess</code> method doesn't allow access
 629      *              to the system properties.
 630      * @see        #setProperties
 631      * @see        java.lang.SecurityException
 632      * @see        java.lang.SecurityManager#checkPropertiesAccess()
 633      * @see        java.util.Properties
 634      */
 635     public static Properties getProperties() {
 636         SecurityManager sm = getSecurityManager();
 637         if (sm != null) {
 638             sm.checkPropertiesAccess();
 639         }
 640 
 641         return props;
 642     }
 643 
 644     /**
 645      * Returns the system-dependent line separator string.  It always
 646      * returns the same value - the initial value of the {@linkplain
 647      * #getProperty(String) system property} {@code line.separator}.
 648      *
 649      * <p>On UNIX systems, it returns {@code "\n"}; on Microsoft
 650      * Windows systems it returns {@code "\r\n"}.
 651      *
 652      * @return the system-dependent line separator string
 653      * @since 1.7
 654      */
 655     public static String lineSeparator() {
 656         return lineSeparator;
 657     }
 658 
 659     private static String lineSeparator;
 660 
 661     /**
 662      * Sets the system properties to the <code>Properties</code>
 663      * argument.
 664      * <p>
 665      * First, if there is a security manager, its
 666      * <code>checkPropertiesAccess</code> method is called with no
 667      * arguments. This may result in a security exception.
 668      * <p>
 669      * The argument becomes the current set of system properties for use
 670      * by the {@link #getProperty(String)} method. If the argument is
 671      * <code>null</code>, then the current set of system properties is
 672      * forgotten.
 673      *
 674      * @param      props   the new system properties.
 675      * @exception  SecurityException  if a security manager exists and its
 676      *             <code>checkPropertiesAccess</code> method doesn't allow access
 677      *              to the system properties.
 678      * @see        #getProperties
 679      * @see        java.util.Properties
 680      * @see        java.lang.SecurityException
 681      * @see        java.lang.SecurityManager#checkPropertiesAccess()
 682      */
 683     public static void setProperties(Properties props) {
 684         SecurityManager sm = getSecurityManager();
 685         if (sm != null) {
 686             sm.checkPropertiesAccess();
 687         }
 688         if (props == null) {
 689             props = new Properties();
 690             initProperties(props);
 691         }
 692         System.props = props;
 693     }
 694 
 695     /**
 696      * Gets the system property indicated by the specified key.
 697      * <p>
 698      * First, if there is a security manager, its
 699      * <code>checkPropertyAccess</code> method is called with the key as
 700      * its argument. This may result in a SecurityException.
 701      * <p>
 702      * If there is no current set of system properties, a set of system
 703      * properties is first created and initialized in the same manner as
 704      * for the <code>getProperties</code> method.
 705      *
 706      * @param      key   the name of the system property.
 707      * @return     the string value of the system property,
 708      *             or <code>null</code> if there is no property with that key.
 709      *
 710      * @exception  SecurityException  if a security manager exists and its
 711      *             <code>checkPropertyAccess</code> method doesn't allow
 712      *              access to the specified system property.
 713      * @exception  NullPointerException if <code>key</code> is
 714      *             <code>null</code>.
 715      * @exception  IllegalArgumentException if <code>key</code> is empty.
 716      * @see        #setProperty
 717      * @see        java.lang.SecurityException
 718      * @see        java.lang.SecurityManager#checkPropertyAccess(java.lang.String)
 719      * @see        java.lang.System#getProperties()
 720      */
 721     public static String getProperty(String key) {
 722         checkKey(key);
 723         SecurityManager sm = getSecurityManager();
 724         if (sm != null) {
 725             sm.checkPropertyAccess(key);
 726         }
 727 
 728         return props.getProperty(key);
 729     }
 730 
 731     /**
 732      * Gets the system property indicated by the specified key.
 733      * <p>
 734      * First, if there is a security manager, its
 735      * <code>checkPropertyAccess</code> method is called with the
 736      * <code>key</code> as its argument.
 737      * <p>
 738      * If there is no current set of system properties, a set of system
 739      * properties is first created and initialized in the same manner as
 740      * for the <code>getProperties</code> method.
 741      *
 742      * @param      key   the name of the system property.
 743      * @param      def   a default value.
 744      * @return     the string value of the system property,
 745      *             or the default value if there is no property with that key.
 746      *
 747      * @exception  SecurityException  if a security manager exists and its
 748      *             <code>checkPropertyAccess</code> method doesn't allow
 749      *             access to the specified system property.
 750      * @exception  NullPointerException if <code>key</code> is
 751      *             <code>null</code>.
 752      * @exception  IllegalArgumentException if <code>key</code> is empty.
 753      * @see        #setProperty
 754      * @see        java.lang.SecurityManager#checkPropertyAccess(java.lang.String)
 755      * @see        java.lang.System#getProperties()
 756      */
 757     public static String getProperty(String key, String def) {
 758         checkKey(key);
 759         SecurityManager sm = getSecurityManager();
 760         if (sm != null) {
 761             sm.checkPropertyAccess(key);
 762         }
 763 
 764         return props.getProperty(key, def);
 765     }
 766 
 767     /**
 768      * Sets the system property indicated by the specified key.
 769      * <p>
 770      * First, if a security manager exists, its
 771      * <code>SecurityManager.checkPermission</code> method
 772      * is called with a <code>PropertyPermission(key, "write")</code>
 773      * permission. This may result in a SecurityException being thrown.
 774      * If no exception is thrown, the specified property is set to the given
 775      * value.
 776      *
 777      * @param      key   the name of the system property.
 778      * @param      value the value of the system property.
 779      * @return     the previous value of the system property,
 780      *             or <code>null</code> if it did not have one.
 781      *
 782      * @exception  SecurityException  if a security manager exists and its
 783      *             <code>checkPermission</code> method doesn't allow
 784      *             setting of the specified property.
 785      * @exception  NullPointerException if <code>key</code> or
 786      *             <code>value</code> is <code>null</code>.
 787      * @exception  IllegalArgumentException if <code>key</code> is empty.
 788      * @see        #getProperty
 789      * @see        java.lang.System#getProperty(java.lang.String)
 790      * @see        java.lang.System#getProperty(java.lang.String, java.lang.String)
 791      * @see        java.util.PropertyPermission
 792      * @see        SecurityManager#checkPermission
 793      * @since      1.2
 794      */
 795     public static String setProperty(String key, String value) {
 796         checkKey(key);
 797         SecurityManager sm = getSecurityManager();
 798         if (sm != null) {
 799             sm.checkPermission(new PropertyPermission(key,
 800                 SecurityConstants.PROPERTY_WRITE_ACTION));
 801         }
 802 
 803         return (String) props.setProperty(key, value);
 804     }
 805 
 806     /**
 807      * Removes the system property indicated by the specified key.
 808      * <p>
 809      * First, if a security manager exists, its
 810      * <code>SecurityManager.checkPermission</code> method
 811      * is called with a <code>PropertyPermission(key, "write")</code>
 812      * permission. This may result in a SecurityException being thrown.
 813      * If no exception is thrown, the specified property is removed.
 814      *
 815      * @param      key   the name of the system property to be removed.
 816      * @return     the previous string value of the system property,
 817      *             or <code>null</code> if there was no property with that key.
 818      *
 819      * @exception  SecurityException  if a security manager exists and its
 820      *             <code>checkPropertyAccess</code> method doesn't allow
 821      *              access to the specified system property.
 822      * @exception  NullPointerException if <code>key</code> is
 823      *             <code>null</code>.
 824      * @exception  IllegalArgumentException if <code>key</code> is empty.
 825      * @see        #getProperty
 826      * @see        #setProperty
 827      * @see        java.util.Properties
 828      * @see        java.lang.SecurityException
 829      * @see        java.lang.SecurityManager#checkPropertiesAccess()
 830      * @since 1.5
 831      */
 832     public static String clearProperty(String key) {
 833         checkKey(key);
 834         SecurityManager sm = getSecurityManager();
 835         if (sm != null) {
 836             sm.checkPermission(new PropertyPermission(key, "write"));
 837         }
 838 
 839         return (String) props.remove(key);
 840     }
 841 
 842     private static void checkKey(String key) {
 843         if (key == null) {
 844             throw new NullPointerException("key can't be null");
 845         }
 846         if (key.equals("")) {
 847             throw new IllegalArgumentException("key can't be empty");
 848         }
 849     }
 850 
 851     /**
 852      * Gets the value of the specified environment variable. An
 853      * environment variable is a system-dependent external named
 854      * value.
 855      *
 856      * <p>If a security manager exists, its
 857      * {@link SecurityManager#checkPermission checkPermission}
 858      * method is called with a
 859      * <code>{@link RuntimePermission}("getenv."+name)</code>
 860      * permission.  This may result in a {@link SecurityException}
 861      * being thrown.  If no exception is thrown the value of the
 862      * variable <code>name</code> is returned.
 863      *
 864      * <p><a name="EnvironmentVSSystemProperties"><i>System
 865      * properties</i> and <i>environment variables</i></a> are both
 866      * conceptually mappings between names and values.  Both
 867      * mechanisms can be used to pass user-defined information to a
 868      * Java process.  Environment variables have a more global effect,
 869      * because they are visible to all descendants of the process
 870      * which defines them, not just the immediate Java subprocess.
 871      * They can have subtly different semantics, such as case
 872      * insensitivity, on different operating systems.  For these
 873      * reasons, environment variables are more likely to have
 874      * unintended side effects.  It is best to use system properties
 875      * where possible.  Environment variables should be used when a
 876      * global effect is desired, or when an external system interface
 877      * requires an environment variable (such as <code>PATH</code>).
 878      *
 879      * <p>On UNIX systems the alphabetic case of <code>name</code> is
 880      * typically significant, while on Microsoft Windows systems it is
 881      * typically not.  For example, the expression
 882      * <code>System.getenv("FOO").equals(System.getenv("foo"))</code>
 883      * is likely to be true on Microsoft Windows.
 884      *
 885      * @param  name the name of the environment variable
 886      * @return the string value of the variable, or <code>null</code>
 887      *         if the variable is not defined in the system environment
 888      * @throws NullPointerException if <code>name</code> is <code>null</code>
 889      * @throws SecurityException
 890      *         if a security manager exists and its
 891      *         {@link SecurityManager#checkPermission checkPermission}
 892      *         method doesn't allow access to the environment variable
 893      *         <code>name</code>
 894      * @see    #getenv()
 895      * @see    ProcessBuilder#environment()
 896      */
 897     public static String getenv(String name) {
 898         SecurityManager sm = getSecurityManager();
 899         if (sm != null) {
 900             sm.checkPermission(new RuntimePermission("getenv."+name));
 901         }
 902 
 903         return ProcessEnvironment.getenv(name);
 904     }
 905 
 906 
 907     /**
 908      * Returns an unmodifiable string map view of the current system environment.
 909      * The environment is a system-dependent mapping from names to
 910      * values which is passed from parent to child processes.
 911      *
 912      * <p>If the system does not support environment variables, an
 913      * empty map is returned.
 914      *
 915      * <p>The returned map will never contain null keys or values.
 916      * Attempting to query the presence of a null key or value will
 917      * throw a {@link NullPointerException}.  Attempting to query
 918      * the presence of a key or value which is not of type
 919      * {@link String} will throw a {@link ClassCastException}.
 920      *
 921      * <p>The returned map and its collection views may not obey the
 922      * general contract of the {@link Object#equals} and
 923      * {@link Object#hashCode} methods.
 924      *
 925      * <p>The returned map is typically case-sensitive on all platforms.
 926      *
 927      * <p>If a security manager exists, its
 928      * {@link SecurityManager#checkPermission checkPermission}
 929      * method is called with a
 930      * <code>{@link RuntimePermission}("getenv.*")</code>
 931      * permission.  This may result in a {@link SecurityException} being
 932      * thrown.
 933      *
 934      * <p>When passing information to a Java subprocess,
 935      * <a href=#EnvironmentVSSystemProperties>system properties</a>
 936      * are generally preferred over environment variables.
 937      *
 938      * @return the environment as a map of variable names to values
 939      * @throws SecurityException
 940      *         if a security manager exists and its
 941      *         {@link SecurityManager#checkPermission checkPermission}
 942      *         method doesn't allow access to the process environment
 943      * @see    #getenv(String)
 944      * @see    ProcessBuilder#environment()
 945      * @since  1.5
 946      */
 947     public static java.util.Map<String,String> getenv() {
 948         SecurityManager sm = getSecurityManager();
 949         if (sm != null) {
 950             sm.checkPermission(new RuntimePermission("getenv.*"));
 951         }
 952 
 953         return ProcessEnvironment.getenv();
 954     }
 955 
 956     /**
 957      * {@code System.Logger} instances log messages that will be
 958      * routed to the underlying logging framework the {@link System.LoggerFinder
 959      * LoggerFinder} uses.
 960      * <p>
 961      * {@code System.Logger} instances are typically obtained from
 962      * the {@link java.lang.System System} class, by calling
 963      * {@link java.lang.System#getLogger(java.lang.String) System.getLogger(loggerName)}
 964      * or {@link java.lang.System#getLogger(java.lang.String, java.util.ResourceBundle)
 965      * System.getLogger(loggerName, bundle)}.
 966      *
 967      * @see java.lang.System#getLogger(java.lang.String)
 968      * @see java.lang.System#getLogger(java.lang.String, java.util.ResourceBundle)
 969      * @see java.lang.System.LoggerFinder
 970      *
 971      * @since 9
 972      *
 973      */
 974     public interface Logger {
 975 
 976         /**
 977          * System {@linkplain Logger loggers} levels.
 978          * <p>
 979          * A level has a {@linkplain #getName() name} and {@linkplain
 980          * #getSeverity() severity}.
 981          * Level values are {@link #ALL}, {@link #TRACE}, {@link #DEBUG},
 982          * {@link #INFO}, {@link #WARNING}, {@link #ERROR}, {@link #OFF},
 983          * by order of increasing severity.
 984          * <br>
 985          * {@link #ALL} and {@link #OFF}
 986          * are simple markers with severities mapped respectively to
 987          * {@link java.lang.Integer#MIN_VALUE Integer.MIN_VALUE} and
 988          * {@link java.lang.Integer#MAX_VALUE Integer.MAX_VALUE}.
 989          * <p>
 990          * <b>Severity values and Mapping to {@code java.util.logging.Level}.</b>
 991          * <p>
 992          * {@linkplain System.Logger.Level System logger levels} are mapped to
 993          * {@linkplain java.util.logging.Level  java.util.logging levels}
 994          * of corresponding severity.
 995          * <br>The mapping is as follows:
 996          * <br><br>
 997          * <table border="1">
 998          * <caption>System.Logger Severity Level Mapping</caption>
 999          * <tr><td><b>System.Logger Levels</b></td>
1000          * <td>{@link Logger.Level#ALL ALL}</td>
1001          * <td>{@link Logger.Level#TRACE TRACE}</td>
1002          * <td>{@link Logger.Level#DEBUG DEBUG}</td>
1003          * <td>{@link Logger.Level#INFO INFO}</td>
1004          * <td>{@link Logger.Level#WARNING WARNING}</td>
1005          * <td>{@link Logger.Level#ERROR ERROR}</td>
1006          * <td>{@link Logger.Level#OFF OFF}</td>
1007          * </tr>
1008          * <tr><td><b>java.util.logging Levels</b></td>
1009          * <td>{@link java.util.logging.Level#ALL ALL}</td>
1010          * <td>{@link java.util.logging.Level#FINER FINER}</td>
1011          * <td>{@link java.util.logging.Level#FINE FINE}</td>
1012          * <td>{@link java.util.logging.Level#INFO INFO}</td>
1013          * <td>{@link java.util.logging.Level#WARNING WARNING}</td>
1014          * <td>{@link java.util.logging.Level#SEVERE SEVERE}</td>
1015          * <td>{@link java.util.logging.Level#OFF OFF}</td>
1016          * </tr>
1017          * </table>
1018          *
1019          * @since 9
1020          *
1021          * @see java.lang.System.LoggerFinder
1022          * @see java.lang.System.Logger
1023          */
1024         public enum Level {
1025 
1026             // for convenience, we're reusing java.util.logging.Level int values
1027             // the mapping logic in sun.util.logging.PlatformLogger depends
1028             // on this.
1029             /**
1030              * A marker to indicate that all levels are enabled.
1031              * This level {@linkplain #getSeverity() severity} is
1032              * {@link Integer#MIN_VALUE}.
1033              */
1034             ALL(Integer.MIN_VALUE),  // typically mapped to/from j.u.l.Level.ALL
1035             /**
1036              * {@code TRACE} level: usually used to log diagnostic information.
1037              * This level {@linkplain #getSeverity() severity} is
1038              * {@code 400}.
1039              */
1040             TRACE(400),   // typically mapped to/from j.u.l.Level.FINER
1041             /**
1042              * {@code DEBUG} level: usually used to log debug information traces.
1043              * This level {@linkplain #getSeverity() severity} is
1044              * {@code 500}.
1045              */
1046             DEBUG(500),   // typically mapped to/from j.u.l.Level.FINEST/FINE/CONFIG
1047             /**
1048              * {@code INFO} level: usually used to log information messages.
1049              * This level {@linkplain #getSeverity() severity} is
1050              * {@code 800}.
1051              */
1052             INFO(800),    // typically mapped to/from j.u.l.Level.INFO
1053             /**
1054              * {@code WARNING} level: usually used to log warning messages.
1055              * This level {@linkplain #getSeverity() severity} is
1056              * {@code 900}.
1057              */
1058             WARNING(900), // typically mapped to/from j.u.l.Level.WARNING
1059             /**
1060              * {@code ERROR} level: usually used to log error messages.
1061              * This level {@linkplain #getSeverity() severity} is
1062              * {@code 1000}.
1063              */
1064             ERROR(1000),  // typically mapped to/from j.u.l.Level.SEVERE
1065             /**
1066              * A marker to indicate that all levels are disabled.
1067              * This level {@linkplain #getSeverity() severity} is
1068              * {@link Integer#MAX_VALUE}.
1069              */
1070             OFF(Integer.MAX_VALUE);  // typically mapped to/from j.u.l.Level.OFF
1071 
1072             private final int severity;
1073 
1074             private Level(int severity) {
1075                 this.severity = severity;
1076             }
1077 
1078             /**
1079              * Returns the name of this level.
1080              * @return this level {@linkplain #name()}.
1081              */
1082             public final String getName() {
1083                 return name();
1084             }
1085 
1086             /**
1087              * Returns the severity of this level.
1088              * A higher severity means a more severe condition.
1089              * @return this level severity.
1090              */
1091             public final int getSeverity() {
1092                 return severity;
1093             }
1094         }
1095 
1096         /**
1097          * Returns the name of this logger.
1098          *
1099          * @return the logger name.
1100          */
1101         public String getName();
1102 
1103         /**
1104          * Checks if a message of the given level would be logged by
1105          * this logger.
1106          *
1107          * @param level the log message level.
1108          * @return {@code true} if the given log message level is currently
1109          *         being logged.
1110          *
1111          * @throws NullPointerException if {@code level} is {@code null}.
1112          */
1113         public boolean isLoggable(Level level);
1114 
1115         /**
1116          * Logs a message.
1117          *
1118          * @implSpec The default implementation for this method calls
1119          * {@code this.log(level, (ResourceBundle)null, msg, (Object[])null);}
1120          *
1121          * @param level the log message level.
1122          * @param msg the string message (or a key in the message catalog, if
1123          * this logger is a {@link
1124          * LoggerFinder#getLocalizedLogger(java.lang.String, java.util.ResourceBundle, java.lang.Class)
1125          * localized logger}); can be {@code null}.
1126          *
1127          * @throws NullPointerException if {@code level} is {@code null}.
1128          */
1129         public default void log(Level level, String msg) {
1130             log(level, (ResourceBundle) null, msg, (Object[]) null);
1131         }
1132 
1133         /**
1134          * Logs a lazily supplied message.
1135          * <p>
1136          * If the logger is currently enabled for the given log message level
1137          * then a message is logged that is the result produced by the
1138          * given supplier function.  Otherwise, the supplier is not operated on.
1139          *
1140          * @implSpec When logging is enabled for the given level, the default
1141          * implementation for this method calls
1142          * {@code this.log(level, (ResourceBundle)null, msgSupplier.get(), (Object[])null);}
1143          *
1144          * @param level the log message level.
1145          * @param msgSupplier a supplier function that produces a message.
1146          *
1147          * @throws NullPointerException if {@code level} is {@code null},
1148          *         or {@code msgSupplier} is {@code null}.
1149          */
1150         public default void log(Level level, Supplier<String> msgSupplier) {
1151             Objects.requireNonNull(msgSupplier);
1152             if (isLoggable(Objects.requireNonNull(level))) {
1153                 log(level, (ResourceBundle) null, msgSupplier.get(), (Object[]) null);
1154             }
1155         }
1156 
1157         /**
1158          * Logs a message produced from the given object.
1159          * <p>
1160          * If the logger is currently enabled for the given log message level then
1161          * a message is logged that, by default, is the result produced from
1162          * calling  toString on the given object.
1163          * Otherwise, the object is not operated on.
1164          *
1165          * @implSpec When logging is enabled for the given level, the default
1166          * implementation for this method calls
1167          * {@code this.log(level, (ResourceBundle)null, obj.toString(), (Object[])null);}
1168          *
1169          * @param level the log message level.
1170          * @param obj the object to log.
1171          *
1172          * @throws NullPointerException if {@code level} is {@code null}, or
1173          *         {@code obj} is {@code null}.
1174          */
1175         public default void log(Level level, Object obj) {
1176             Objects.requireNonNull(obj);
1177             if (isLoggable(Objects.requireNonNull(level))) {
1178                 this.log(level, (ResourceBundle) null, obj.toString(), (Object[]) null);
1179             }
1180         }
1181 
1182         /**
1183          * Logs a message associated with a given throwable.
1184          *
1185          * @implSpec The default implementation for this method calls
1186          * {@code this.log(level, (ResourceBundle)null, msg, thrown);}
1187          *
1188          * @param level the log message level.
1189          * @param msg the string message (or a key in the message catalog, if
1190          * this logger is a {@link
1191          * LoggerFinder#getLocalizedLogger(java.lang.String, java.util.ResourceBundle, java.lang.Class)
1192          * localized logger}); can be {@code null}.
1193          * @param thrown a {@code Throwable} associated with the log message;
1194          *        can be {@code null}.
1195          *
1196          * @throws NullPointerException if {@code level} is {@code null}.
1197          */
1198         public default void log(Level level, String msg, Throwable thrown) {
1199             this.log(level, null, msg, thrown);
1200         }
1201 
1202         /**
1203          * Logs a lazily supplied message associated with a given throwable.
1204          * <p>
1205          * If the logger is currently enabled for the given log message level
1206          * then a message is logged that is the result produced by the
1207          * given supplier function.  Otherwise, the supplier is not operated on.
1208          *
1209          * @implSpec When logging is enabled for the given level, the default
1210          * implementation for this method calls
1211          * {@code this.log(level, (ResourceBundle)null, msgSupplier.get(), thrown);}
1212          *
1213          * @param level one of the log message level identifiers.
1214          * @param msgSupplier a supplier function that produces a message.
1215          * @param thrown a {@code Throwable} associated with log message;
1216          *               can be {@code null}.
1217          *
1218          * @throws NullPointerException if {@code level} is {@code null}, or
1219          *                               {@code msgSupplier} is {@code null}.
1220          */
1221         public default void log(Level level, Supplier<String> msgSupplier,
1222                 Throwable thrown) {
1223             Objects.requireNonNull(msgSupplier);
1224             if (isLoggable(Objects.requireNonNull(level))) {
1225                 this.log(level, null, msgSupplier.get(), thrown);
1226             }
1227         }
1228 
1229         /**
1230          * Logs a message with an optional list of parameters.
1231          *
1232          * @implSpec The default implementation for this method calls
1233          * {@code this.log(level, (ResourceBundle)null, format, params);}
1234          *
1235          * @param level one of the log message level identifiers.
1236          * @param format the string message format in {@link
1237          * java.text.MessageFormat} format, (or a key in the message
1238          * catalog, if this logger is a {@link
1239          * LoggerFinder#getLocalizedLogger(java.lang.String, java.util.ResourceBundle, java.lang.Class)
1240          * localized logger}); can be {@code null}.
1241          * @param params an optional list of parameters to the message (may be
1242          * none).
1243          *
1244          * @throws NullPointerException if {@code level} is {@code null}.
1245          */
1246         public default void log(Level level, String format, Object... params) {
1247             this.log(level, null, format, params);
1248         }
1249 
1250         /**
1251          * Logs a localized message associated with a given throwable.
1252          * <p>
1253          * If the given resource bundle is non-{@code null},  the {@code msg}
1254          * string is localized using the given resource bundle.
1255          * Otherwise the {@code msg} string is not localized.
1256          *
1257          * @param level the log message level.
1258          * @param bundle a resource bundle to localize {@code msg}; can be
1259          * {@code null}.
1260          * @param msg the string message (or a key in the message catalog,
1261          *            if {@code bundle} is not {@code null}); can be {@code null}.
1262          * @param thrown a {@code Throwable} associated with the log message;
1263          *        can be {@code null}.
1264          *
1265          * @throws NullPointerException if {@code level} is {@code null}.
1266          */
1267         public void log(Level level, ResourceBundle bundle, String msg,
1268                 Throwable thrown);
1269 
1270         /**
1271          * Logs a message with resource bundle and an optional list of
1272          * parameters.
1273          * <p>
1274          * If the given resource bundle is non-{@code null},  the {@code format}
1275          * string is localized using the given resource bundle.
1276          * Otherwise the {@code format} string is not localized.
1277          *
1278          * @param level the log message level.
1279          * @param bundle a resource bundle to localize {@code format}; can be
1280          * {@code null}.
1281          * @param format the string message format in {@link
1282          * java.text.MessageFormat} format, (or a key in the message
1283          * catalog if {@code bundle} is not {@code null}); can be {@code null}.
1284          * @param params an optional list of parameters to the message (may be
1285          * none).
1286          *
1287          * @throws NullPointerException if {@code level} is {@code null}.
1288          */
1289         public void log(Level level, ResourceBundle bundle, String format,
1290                 Object... params);
1291 
1292 
1293     }
1294 
1295     /**
1296      * The {@code LoggerFinder} service is responsible for creating, managing,
1297      * and configuring loggers to the underlying framework it uses.
1298      * <p>
1299      * A logger finder is a concrete implementation of this class that has a
1300      * zero-argument constructor and implements the abstract methods defined
1301      * by this class.
1302      * The loggers returned from a logger finder are capable of routing log
1303      * messages to the logging backend this provider supports.
1304      * A given invocation of the Java Runtime maintains a single
1305      * system-wide LoggerFinder instance that is loaded as follows:
1306      * <ul>
1307      *    <li>First it finds any custom {@code LoggerFinder} provider
1308      *        using the {@link java.util.ServiceLoader} facility with the
1309      *        {@linkplain ClassLoader#getSystemClassLoader() system class
1310      *        loader}.</li>
1311      *    <li>If no {@code LoggerFinder} provider is found, the system default
1312      *        {@code LoggerFinder} implementation will be used.</li>
1313      * </ul>
1314      * <p>
1315      * An application can replace the logging backend
1316      * <i>even when the java.logging module is present</i>, by simply providing
1317      * and declaring an implementation of the {@link LoggerFinder} service.
1318      * <p>
1319      * <b>Default Implementation</b>
1320      * <p>
1321      * The system default {@code LoggerFinder} implementation uses
1322      * {@code java.util.logging} as the backend framework when the
1323      * {@code java.logging} module is present.
1324      * It returns a {@linkplain System.Logger logger} instance
1325      * that will route log messages to a {@link java.util.logging.Logger
1326      * java.util.logging.Logger}. Otherwise, if {@code java.logging} is not
1327      * present, the default implementation will return a simple logger
1328      * instance that will route log messages of {@code INFO} level and above to
1329      * the console ({@code System.err}).
1330      * <p>
1331      * <b>Logging Configuration</b>
1332      * <p>
1333      * {@linkplain Logger Logger} instances obtained from the
1334      * {@code LoggerFinder} factory methods are not directly configurable by
1335      * the application. Configuration is the responsibility of the underlying
1336      * logging backend, and usually requires using APIs specific to that backend.
1337      * <p>For the default {@code LoggerFinder} implementation
1338      * using {@code java.util.logging} as its backend, refer to
1339      * {@link java.util.logging java.util.logging} for logging configuration.
1340      * For the default {@code LoggerFinder} implementation returning simple loggers
1341      * when the {@code java.logging} module is absent, the configuration
1342      * is implementation dependent.
1343      * <p>
1344      * Usually an application that uses a logging framework will log messages
1345      * through a logger facade defined (or supported) by that framework.
1346      * Applications that wish to use an external framework should log
1347      * through the facade associated with that framework.
1348      * <p>
1349      * A system class that needs to log messages will typically obtain
1350      * a {@link System.Logger} instance to route messages to the logging
1351      * framework selected by the application.
1352      * <p>
1353      * Libraries and classes that only need loggers to produce log messages
1354      * should not attempt to configure loggers by themselves, as that
1355      * would make them dependent from a specific implementation of the
1356      * {@code LoggerFinder} service.
1357      * <p>
1358      * In addition, when a security manager is present, loggers provided to
1359      * system classes should not be directly configurable through the logging
1360      * backend without requiring permissions.
1361      * <br>
1362      * It is the responsibility of the provider of
1363      * the concrete {@code LoggerFinder} implementation to ensure that
1364      * these loggers are not configured by untrusted code without proper
1365      * permission checks, as configuration performed on such loggers usually
1366      * affects all applications in the same Java Runtime.
1367      * <p>
1368      * <b>Message Levels and Mapping to backend levels</b>
1369      * <p>
1370      * A logger finder is responsible for mapping from a {@code
1371      * System.Logger.Level} to a level supported by the logging backend it uses.
1372      * <br>The default LoggerFinder using {@code java.util.logging} as the backend
1373      * maps {@code System.Logger} levels to
1374      * {@linkplain java.util.logging.Level java.util.logging} levels
1375      * of corresponding severity - as described in {@link Logger.Level
1376      * Logger.Level}.
1377      *
1378      * @see java.lang.System
1379      * @see java.lang.System.Logger
1380      *
1381      * @since 9
1382      */
1383     public static abstract class LoggerFinder {
1384         /**
1385          * The {@code RuntimePermission("loggerFinder")} is
1386          * necessary to subclass and instantiate the {@code LoggerFinder} class,
1387          * as well as to obtain loggers from an instance of that class.
1388          */
1389         static final RuntimePermission LOGGERFINDER_PERMISSION =
1390                 new RuntimePermission("loggerFinder");
1391 
1392         /**
1393          * Creates a new instance of {@code LoggerFinder}.
1394          *
1395          * @implNote It is recommended that a {@code LoggerFinder} service
1396          *   implementation does not perform any heavy initialization in its
1397          *   constructor, in order to avoid possible risks of deadlock or class
1398          *   loading cycles during the instantiation of the service provider.
1399          *
1400          * @throws SecurityException if a security manager is present and its
1401          *         {@code checkPermission} method doesn't allow the
1402          *         {@code RuntimePermission("loggerFinder")}.
1403          */
1404         protected LoggerFinder() {
1405             this(checkPermission());
1406         }
1407 
1408         private LoggerFinder(Void unused) {
1409             // nothing to do.
1410         }
1411 
1412         private static Void checkPermission() {
1413             final SecurityManager sm = System.getSecurityManager();
1414             if (sm != null) {
1415                 sm.checkPermission(LOGGERFINDER_PERMISSION);
1416             }
1417             return null;
1418         }
1419 
1420         /**
1421          * Returns an instance of {@link Logger Logger}
1422          * for the given {@code caller}.
1423          *
1424          * @param name the name of the logger.
1425          * @param caller the class for which the logger is being requested;
1426          *               can be {@code null}.
1427          *
1428          * @return a {@link Logger logger} suitable for the given caller's
1429          *         use.
1430          * @throws NullPointerException if {@code name} is {@code null} or
1431          *        {@code caller} is {@code null}.
1432          * @throws SecurityException if a security manager is present and its
1433          *         {@code checkPermission} method doesn't allow the
1434          *         {@code RuntimePermission("loggerFinder")}.
1435          */
1436         public abstract Logger getLogger(String name, /* Module */ Class<?> caller);
1437 
1438         /**
1439          * Returns a localizable instance of {@link Logger Logger}
1440          * for the given {@code caller}.
1441          * The returned logger will use the provided resource bundle for
1442          * message localization.
1443          *
1444          * @implSpec By default, this method calls {@link
1445          * #getLogger(java.lang.String, java.lang.Class)
1446          * this.getLogger(name, caller)} to obtain a logger, then wraps that
1447          * logger in a {@link Logger} instance where all methods that do not
1448          * take a {@link ResourceBundle} as parameter are redirected to one
1449          * which does - passing the given {@code bundle} for
1450          * localization. So for instance, a call to {@link
1451          * Logger#log(Level, String) Logger.log(Level.INFO, msg)}
1452          * will end up as a call to {@link
1453          * Logger#log(Level, ResourceBundle, String, Object...)
1454          * Logger.log(Level.INFO, bundle, msg, (Object[])null)} on the wrapped
1455          * logger instance.
1456          * Note however that by default, string messages returned by {@link
1457          * java.util.function.Supplier Supplier&lt;String&gt;} will not be
1458          * localized, as it is assumed that such strings are messages which are
1459          * already constructed, rather than keys in a resource bundle.
1460          * <p>
1461          * An implementation of {@code LoggerFinder} may override this method,
1462          * for example, when the underlying logging backend provides its own
1463          * mechanism for localizing log messages, then such a
1464          * {@code LoggerFinder} would be free to return a logger
1465          * that makes direct use of the mechanism provided by the backend.
1466          *
1467          * @param name    the name of the logger.
1468          * @param bundle  a resource bundle; can be {@code null}.
1469          * @param caller the class for which the logger is being requested.
1470          * @return an instance of {@link Logger Logger}  which will use the
1471          * provided resource bundle for message localization.
1472          *
1473          * @throws NullPointerException if {@code name} is {@code null} or
1474          *         {@code caller} is {@code null}.
1475          * @throws SecurityException if a security manager is present and its
1476          *         {@code checkPermission} method doesn't allow the
1477          *         {@code RuntimePermission("loggerFinder")}.
1478          */
1479         public Logger getLocalizedLogger(String name, ResourceBundle bundle,
1480                                           /* Module */ Class<?> caller) {
1481             return new LocalizedLoggerWrapper<>(getLogger(name, caller), bundle);
1482         }
1483 
1484         /**
1485          * Returns the {@code LoggerFinder} instance. There is one
1486          * single system-wide {@code LoggerFinder} instance in
1487          * the Java Runtime.  See the class specification of how the
1488          * {@link LoggerFinder LoggerFinder} implementation is located and
1489          * loaded.
1490 
1491          * @return the {@link LoggerFinder LoggerFinder} instance.
1492          * @throws SecurityException if a security manager is present and its
1493          *         {@code checkPermission} method doesn't allow the
1494          *         {@code RuntimePermission("loggerFinder")}.
1495          */
1496         public static LoggerFinder getLoggerFinder() {
1497             final SecurityManager sm = System.getSecurityManager();
1498             if (sm != null) {
1499                 sm.checkPermission(LOGGERFINDER_PERMISSION);
1500             }
1501             return accessProvider();
1502         }
1503 
1504 
1505         private static volatile LoggerFinder service;
1506         static LoggerFinder accessProvider() {
1507             // We do not need to synchronize: LoggerFinderLoader will
1508             // always return the same instance, so if we don't have it,
1509             // just fetch it again.
1510             if (service == null) {
1511                 PrivilegedAction<LoggerFinder> pa =
1512                         () -> LoggerFinderLoader.getLoggerFinder();
1513                 service = AccessController.doPrivileged(pa, null,
1514                         LOGGERFINDER_PERMISSION);
1515             }
1516             return service;
1517         }
1518 
1519     }
1520 
1521 
1522     /**
1523      * Returns an instance of {@link Logger Logger} for the caller's
1524      * use.
1525      *
1526      * @implSpec
1527      * Instances returned by this method route messages to loggers
1528      * obtained by calling {@link LoggerFinder#getLogger(java.lang.String, java.lang.Class)
1529      * LoggerFinder.getLogger(name, caller)}.
1530      *
1531      * @apiNote
1532      * This method may defer calling the {@link
1533      * LoggerFinder#getLogger(java.lang.String, java.lang.Class)
1534      * LoggerFinder.getLogger} method to create an actual logger supplied by
1535      * the logging backend, for instance, to allow loggers to be obtained during
1536      * the system initialization time.
1537      *
1538      * @param name the name of the logger.
1539      * @return an instance of {@link Logger} that can be used by the calling
1540      *         class.
1541      * @throws NullPointerException if {@code name} is {@code null}.
1542      *
1543      * @since 9
1544      */
1545     @CallerSensitive
1546     public static Logger getLogger(String name) {
1547         Objects.requireNonNull(name);
1548         final Class<?> caller = Reflection.getCallerClass();
1549         return LazyLoggers.getLogger(name, caller);
1550     }
1551 
1552     /**
1553      * Returns a localizable instance of {@link Logger
1554      * Logger} for the caller's use.
1555      * The returned logger will use the provided resource bundle for message
1556      * localization.
1557      *
1558      * @implSpec
1559      * The returned logger will perform message localization as specified
1560      * by {@link LoggerFinder#getLocalizedLogger(java.lang.String,
1561      * java.util.ResourceBundle, java.lang.Class)
1562      * LoggerFinder.getLocalizedLogger(name, bundle, caller}.
1563      *
1564      * @apiNote
1565      * This method is intended to be used after the system is fully initialized.
1566      * This method may trigger the immediate loading and initialization
1567      * of the {@link LoggerFinder} service, which may cause issues if the
1568      * Java Runtime is not ready to initialize the concrete service
1569      * implementation yet.
1570      * System classes which may be loaded early in the boot sequence and
1571      * need to log localized messages should create a logger using
1572      * {@link #getLogger(java.lang.String)} and then use the log methods that
1573      * take a resource bundle as parameter.
1574      *
1575      * @param name    the name of the logger.
1576      * @param bundle  a resource bundle.
1577      * @return an instance of {@link Logger} which will use the provided
1578      * resource bundle for message localization.
1579      * @throws NullPointerException if {@code name} is {@code null} or
1580      *         {@code bundle} is {@code null}.
1581      *
1582      * @since 9
1583      */
1584     @CallerSensitive
1585     public static Logger getLogger(String name, ResourceBundle bundle) {
1586         final ResourceBundle rb = Objects.requireNonNull(bundle);
1587         Objects.requireNonNull(name);
1588         final Class<?> caller = Reflection.getCallerClass();
1589         final SecurityManager sm = System.getSecurityManager();
1590         // We don't use LazyLoggers if a resource bundle is specified.
1591         // Bootstrap sensitive classes in the JDK do not use resource bundles
1592         // when logging. This could be revisited later, if it needs to.
1593         if (sm != null) {
1594             return AccessController.doPrivileged((PrivilegedAction<Logger>)
1595                     () -> LoggerFinder.accessProvider().getLocalizedLogger(name, rb, caller),
1596                     null,
1597                     LoggerFinder.LOGGERFINDER_PERMISSION);
1598         }
1599         return LoggerFinder.accessProvider().getLocalizedLogger(name, rb, caller);
1600     }
1601 
1602     /**
1603      * Terminates the currently running Java Virtual Machine. The
1604      * argument serves as a status code; by convention, a nonzero status
1605      * code indicates abnormal termination.
1606      * <p>
1607      * This method calls the <code>exit</code> method in class
1608      * <code>Runtime</code>. This method never returns normally.
1609      * <p>
1610      * The call <code>System.exit(n)</code> is effectively equivalent to
1611      * the call:
1612      * <blockquote><pre>
1613      * Runtime.getRuntime().exit(n)
1614      * </pre></blockquote>
1615      *
1616      * @param      status   exit status.
1617      * @throws  SecurityException
1618      *        if a security manager exists and its <code>checkExit</code>
1619      *        method doesn't allow exit with the specified status.
1620      * @see        java.lang.Runtime#exit(int)
1621      */
1622     public static void exit(int status) {
1623         Runtime.getRuntime().exit(status);
1624     }
1625 
1626     /**
1627      * Runs the garbage collector.
1628      * <p>
1629      * Calling the <code>gc</code> method suggests that the Java Virtual
1630      * Machine expend effort toward recycling unused objects in order to
1631      * make the memory they currently occupy available for quick reuse.
1632      * When control returns from the method call, the Java Virtual
1633      * Machine has made a best effort to reclaim space from all discarded
1634      * objects.
1635      * <p>
1636      * The call <code>System.gc()</code> is effectively equivalent to the
1637      * call:
1638      * <blockquote><pre>
1639      * Runtime.getRuntime().gc()
1640      * </pre></blockquote>
1641      *
1642      * @see     java.lang.Runtime#gc()
1643      */
1644     public static void gc() {
1645         Runtime.getRuntime().gc();
1646     }
1647 
1648     /**
1649      * Runs the finalization methods of any objects pending finalization.
1650      * <p>
1651      * Calling this method suggests that the Java Virtual Machine expend
1652      * effort toward running the <code>finalize</code> methods of objects
1653      * that have been found to be discarded but whose <code>finalize</code>
1654      * methods have not yet been run. When control returns from the
1655      * method call, the Java Virtual Machine has made a best effort to
1656      * complete all outstanding finalizations.
1657      * <p>
1658      * The call <code>System.runFinalization()</code> is effectively
1659      * equivalent to the call:
1660      * <blockquote><pre>
1661      * Runtime.getRuntime().runFinalization()
1662      * </pre></blockquote>
1663      *
1664      * @see     java.lang.Runtime#runFinalization()
1665      */
1666     public static void runFinalization() {
1667         Runtime.getRuntime().runFinalization();
1668     }
1669 
1670     /**
1671      * Enable or disable finalization on exit; doing so specifies that the
1672      * finalizers of all objects that have finalizers that have not yet been
1673      * automatically invoked are to be run before the Java runtime exits.
1674      * By default, finalization on exit is disabled.
1675      *
1676      * <p>If there is a security manager,
1677      * its <code>checkExit</code> method is first called
1678      * with 0 as its argument to ensure the exit is allowed.
1679      * This could result in a SecurityException.
1680      *
1681      * @deprecated  This method is inherently unsafe.  It may result in
1682      *      finalizers being called on live objects while other threads are
1683      *      concurrently manipulating those objects, resulting in erratic
1684      *      behavior or deadlock.
1685      * @param value indicating enabling or disabling of finalization
1686      * @throws  SecurityException
1687      *        if a security manager exists and its <code>checkExit</code>
1688      *        method doesn't allow the exit.
1689      *
1690      * @see     java.lang.Runtime#exit(int)
1691      * @see     java.lang.Runtime#gc()
1692      * @see     java.lang.SecurityManager#checkExit(int)
1693      * @since   1.1
1694      */
1695     @Deprecated
1696     public static void runFinalizersOnExit(boolean value) {
1697         Runtime.runFinalizersOnExit(value);
1698     }
1699 
1700     /**
1701      * Loads the native library specified by the filename argument.  The filename
1702      * argument must be an absolute path name.
1703      *
1704      * If the filename argument, when stripped of any platform-specific library
1705      * prefix, path, and file extension, indicates a library whose name is,
1706      * for example, L, and a native library called L is statically linked
1707      * with the VM, then the JNI_OnLoad_L function exported by the library
1708      * is invoked rather than attempting to load a dynamic library.
1709      * A filename matching the argument does not have to exist in the
1710      * file system.
1711      * See the JNI Specification for more details.
1712      *
1713      * Otherwise, the filename argument is mapped to a native library image in
1714      * an implementation-dependent manner.
1715      *
1716      * <p>
1717      * The call <code>System.load(name)</code> is effectively equivalent
1718      * to the call:
1719      * <blockquote><pre>
1720      * Runtime.getRuntime().load(name)
1721      * </pre></blockquote>
1722      *
1723      * @param      filename   the file to load.
1724      * @exception  SecurityException  if a security manager exists and its
1725      *             <code>checkLink</code> method doesn't allow
1726      *             loading of the specified dynamic library
1727      * @exception  UnsatisfiedLinkError  if either the filename is not an
1728      *             absolute path name, the native library is not statically
1729      *             linked with the VM, or the library cannot be mapped to
1730      *             a native library image by the host system.
1731      * @exception  NullPointerException if <code>filename</code> is
1732      *             <code>null</code>
1733      * @see        java.lang.Runtime#load(java.lang.String)
1734      * @see        java.lang.SecurityManager#checkLink(java.lang.String)
1735      */
1736     @CallerSensitive
1737     public static void load(String filename) {
1738         Runtime.getRuntime().load0(Reflection.getCallerClass(), filename);
1739     }
1740 
1741     /**
1742      * Loads the native library specified by the <code>libname</code>
1743      * argument.  The <code>libname</code> argument must not contain any platform
1744      * specific prefix, file extension or path. If a native library
1745      * called <code>libname</code> is statically linked with the VM, then the
1746      * JNI_OnLoad_<code>libname</code> function exported by the library is invoked.
1747      * See the JNI Specification for more details.
1748      *
1749      * Otherwise, the libname argument is loaded from a system library
1750      * location and mapped to a native library image in an implementation-
1751      * dependent manner.
1752      * <p>
1753      * The call <code>System.loadLibrary(name)</code> is effectively
1754      * equivalent to the call
1755      * <blockquote><pre>
1756      * Runtime.getRuntime().loadLibrary(name)
1757      * </pre></blockquote>
1758      *
1759      * @param      libname   the name of the library.
1760      * @exception  SecurityException  if a security manager exists and its
1761      *             <code>checkLink</code> method doesn't allow
1762      *             loading of the specified dynamic library
1763      * @exception  UnsatisfiedLinkError if either the libname argument
1764      *             contains a file path, the native library is not statically
1765      *             linked with the VM,  or the library cannot be mapped to a
1766      *             native library image by the host system.
1767      * @exception  NullPointerException if <code>libname</code> is
1768      *             <code>null</code>
1769      * @see        java.lang.Runtime#loadLibrary(java.lang.String)
1770      * @see        java.lang.SecurityManager#checkLink(java.lang.String)
1771      */
1772     @CallerSensitive
1773     public static void loadLibrary(String libname) {
1774         Runtime.getRuntime().loadLibrary0(Reflection.getCallerClass(), libname);
1775     }
1776 
1777     /**
1778      * Maps a library name into a platform-specific string representing
1779      * a native library.
1780      *
1781      * @param      libname the name of the library.
1782      * @return     a platform-dependent native library name.
1783      * @exception  NullPointerException if <code>libname</code> is
1784      *             <code>null</code>
1785      * @see        java.lang.System#loadLibrary(java.lang.String)
1786      * @see        java.lang.ClassLoader#findLibrary(java.lang.String)
1787      * @since      1.2
1788      */
1789     public static native String mapLibraryName(String libname);
1790 
1791     /**
1792      * Create PrintStream for stdout/err based on encoding.
1793      */
1794     private static PrintStream newPrintStream(FileOutputStream fos, String enc) {
1795        if (enc != null) {
1796             try {
1797                 return new PrintStream(new BufferedOutputStream(fos, 128), true, enc);
1798             } catch (UnsupportedEncodingException uee) {}
1799         }
1800         return new PrintStream(new BufferedOutputStream(fos, 128), true);
1801     }
1802 
1803 
1804     /**
1805      * Initialize the system class.  Called after thread initialization.
1806      */
1807     private static void initializeSystemClass() {
1808 
1809         // VM might invoke JNU_NewStringPlatform() to set those encoding
1810         // sensitive properties (user.home, user.name, boot.class.path, etc.)
1811         // during "props" initialization, in which it may need access, via
1812         // System.getProperty(), to the related system encoding property that
1813         // have been initialized (put into "props") at early stage of the
1814         // initialization. So make sure the "props" is available at the
1815         // very beginning of the initialization and all system properties to
1816         // be put into it directly.
1817         props = new Properties();
1818         initProperties(props);  // initialized by the VM
1819 
1820         // There are certain system configurations that may be controlled by
1821         // VM options such as the maximum amount of direct memory and
1822         // Integer cache size used to support the object identity semantics
1823         // of autoboxing.  Typically, the library will obtain these values
1824         // from the properties set by the VM.  If the properties are for
1825         // internal implementation use only, these properties should be
1826         // removed from the system properties.
1827         //
1828         // See java.lang.Integer.IntegerCache and the
1829         // VM.saveAndRemoveProperties method for example.
1830         //
1831         // Save a private copy of the system properties object that
1832         // can only be accessed by the internal implementation.  Remove
1833         // certain system properties that are not intended for public access.
1834         VM.saveAndRemoveProperties(props);
1835 
1836 
1837         lineSeparator = props.getProperty("line.separator");
1838         sun.misc.Version.init();
1839 
1840         FileInputStream fdIn = new FileInputStream(FileDescriptor.in);
1841         FileOutputStream fdOut = new FileOutputStream(FileDescriptor.out);
1842         FileOutputStream fdErr = new FileOutputStream(FileDescriptor.err);
1843         setIn0(new BufferedInputStream(fdIn));
1844         setOut0(newPrintStream(fdOut, props.getProperty("sun.stdout.encoding")));
1845         setErr0(newPrintStream(fdErr, props.getProperty("sun.stderr.encoding")));
1846 
1847         // Load the zip library now in order to keep java.util.zip.ZipFile
1848         // from trying to use itself to load this library later.
1849         loadLibrary("zip");
1850 
1851         // Setup Java signal handlers for HUP, TERM, and INT (where available).
1852         Terminator.setup();
1853 
1854         // Initialize any miscellaneous operating system settings that need to be
1855         // set for the class libraries. Currently this is no-op everywhere except
1856         // for Windows where the process-wide error mode is set before the java.io
1857         // classes are used.
1858         VM.initializeOSEnvironment();
1859 
1860         // The main thread is not added to its thread group in the same
1861         // way as other threads; we must do it ourselves here.
1862         Thread current = Thread.currentThread();
1863         current.getThreadGroup().add(current);
1864 
1865         // register shared secrets
1866         setJavaLangAccess();
1867 
1868         // Subsystems that are invoked during initialization can invoke
1869         // VM.isBooted() in order to avoid doing things that should
1870         // wait until the application class loader has been set up.
1871         // IMPORTANT: Ensure that this remains the last initialization action!
1872         VM.booted();
1873     }
1874 
1875     private static void setJavaLangAccess() {
1876         // Allow privileged classes outside of java.lang
1877         SharedSecrets.setJavaLangAccess(new JavaLangAccess(){
1878             public sun.reflect.ConstantPool getConstantPool(Class<?> klass) {
1879                 return klass.getConstantPool();
1880             }
1881             public boolean casAnnotationType(Class<?> klass, AnnotationType oldType, AnnotationType newType) {
1882                 return klass.casAnnotationType(oldType, newType);
1883             }
1884             public AnnotationType getAnnotationType(Class<?> klass) {
1885                 return klass.getAnnotationType();
1886             }
1887             public Map<Class<? extends Annotation>, Annotation> getDeclaredAnnotationMap(Class<?> klass) {
1888                 return klass.getDeclaredAnnotationMap();
1889             }
1890             public byte[] getRawClassAnnotations(Class<?> klass) {
1891                 return klass.getRawAnnotations();
1892             }
1893             public byte[] getRawClassTypeAnnotations(Class<?> klass) {
1894                 return klass.getRawTypeAnnotations();
1895             }
1896             public byte[] getRawExecutableTypeAnnotations(Executable executable) {
1897                 return Class.getExecutableTypeAnnotationBytes(executable);
1898             }
1899             public <E extends Enum<E>>
1900                     E[] getEnumConstantsShared(Class<E> klass) {
1901                 return klass.getEnumConstantsShared();
1902             }
1903             public void blockedOn(Thread t, Interruptible b) {
1904                 t.blockedOn(b);
1905             }
1906             public void registerShutdownHook(int slot, boolean registerShutdownInProgress, Runnable hook) {
1907                 Shutdown.add(slot, registerShutdownInProgress, hook);
1908             }
1909             public String newStringUnsafe(char[] chars) {
1910                 return new String(chars, true);
1911             }
1912             public Thread newThreadWithAcc(Runnable target, AccessControlContext acc) {
1913                 return new Thread(target, acc);
1914             }
1915             public void invokeFinalize(Object o) throws Throwable {
1916                 o.finalize();
1917             }
1918             public String fastUUID(long lsb, long msb) {
1919                 return Long.fastUUID(lsb, msb);
1920             }
1921         });
1922     }
1923 }