       1 /*
       2  * Copyright (c) 1994, 2021, 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.BufferedInputStream;
      28 import java.io.BufferedOutputStream;
      29 import java.io.Console;
      30 import java.io.FileDescriptor;
      31 import java.io.FileInputStream;
      32 import java.io.FileOutputStream;
      33 import java.io.IOException;
      34 import java.io.InputStream;
      35 import java.io.PrintStream;
      36 import java.io.UnsupportedEncodingException;
      37 import java.lang.annotation.Annotation;
      38 import java.lang.invoke.MethodHandle;
      39 import java.lang.invoke.MethodType;
      40 import java.lang.invoke.StringConcatFactory;
      41 import java.lang.module.ModuleDescriptor;
      42 import java.lang.reflect.Constructor;
      43 import java.lang.reflect.Executable;
      44 import java.lang.reflect.Method;
      45 import java.lang.reflect.Modifier;
      46 import java.net.URI;
      47 import java.nio.charset.CharacterCodingException;
      48 import java.security.AccessControlContext;
      49 import java.security.ProtectionDomain;
      50 import java.security.AccessController;
      51 import java.security.PrivilegedAction;
      52 import java.nio.channels.Channel;
      53 import java.nio.channels.spi.SelectorProvider;
      54 import java.nio.charset.Charset;
      55 import java.util.List;
      56 import java.util.Map;
      57 import java.util.Objects;
      58 import java.util.Properties;
      59 import java.util.PropertyPermission;
      60 import java.util.ResourceBundle;
      61 import java.util.Set;
      62 import java.util.function.Supplier;
      63 import java.util.concurrent.ConcurrentHashMap;
      64 import java.util.stream.Stream;
      65
      66 import jdk.internal.misc.Unsafe;
      67 import jdk.internal.util.StaticProperty;
      68 import jdk.internal.module.ModuleBootstrap;
      69 import jdk.internal.module.ServicesCatalog;
      70 import jdk.internal.reflect.CallerSensitive;
      71 import jdk.internal.reflect.Reflection;
      72 import jdk.internal.access.JavaLangAccess;
      73 import jdk.internal.access.SharedSecrets;
      74 import jdk.internal.misc.VM;
      75 import jdk.internal.logger.LoggerFinderLoader;
      76 import jdk.internal.logger.LazyLoggers;
      77 import jdk.internal.logger.LocalizedLoggerWrapper;
      78 import jdk.internal.util.SystemProps;
      79 import jdk.internal.vm.annotation.IntrinsicCandidate;
      80 import jdk.internal.vm.annotation.Stable;
      81 import sun.nio.fs.DefaultFileSystemProvider;
      82 import sun.reflect.annotation.AnnotationType;
      83 import sun.nio.ch.Interruptible;
      84 import sun.security.util.SecurityConstants;
      85
      86 /**
      87  * The {@code System} class contains several useful class fields
      88  * and methods. It cannot be instantiated.
      89  *
      90  * Among the facilities provided by the {@code System} class
      91  * are standard input, standard output, and error output streams;
      92  * access to externally defined properties and environment
      93  * variables; a means of loading files and libraries; and a utility
      94  * method for quickly copying a portion of an array.
      95  *
      96  * @since   1.0
      97  */
      98 public final class System {
      99     /* Register the natives via the static initializer.
     100      *
     101      * The VM will invoke the initPhase1 method to complete the initialization
     102      * of this class separate from <clinit>.
     103      */
     104     private static native void registerNatives();
     105     static {
     106         registerNatives();
     107     }
     108
     109     /** Don't let anyone instantiate this class */
     110     private System() {
     111     }
     112
     113     /**
     114      * The "standard" input stream. This stream is already
     115      * open and ready to supply input data. Typically this stream
     116      * corresponds to keyboard input or another input source specified by
     117      * the host environment or user. In case this stream is wrapped
     118      * in a {@link java.io.InputStreamReader}, {@link Console#charset()}
     119      * should be used for the charset, or consider using
     120      * {@link Console#reader()}.
     121      *
     122      * @see Console#charset()
     123      * @see Console#reader()
     124      */
     125     public static final InputStream in = null;
     126
     127     /**
     128      * The "standard" output stream. This stream is already
     129      * open and ready to accept output data. Typically this stream
     130      * corresponds to display output or another output destination
     131      * specified by the host environment or user. The encoding used
     132      * in the conversion from characters to bytes is equivalent to
     133      * {@link Console#charset()} if the {@code Console} exists,
     134      * {@link Charset#defaultCharset()} otherwise.
     135      * <p>
     136      * For simple stand-alone Java applications, a typical way to write
     137      * a line of output data is:
     138      * <blockquote><pre>
     139      *     System.out.println(data)
     140      * </pre></blockquote>
     141      * <p>
     142      * See the {@code println} methods in class {@code PrintStream}.
     143      *
     144      * @see     java.io.PrintStream#println()
     145      * @see     java.io.PrintStream#println(boolean)
     146      * @see     java.io.PrintStream#println(char)
     147      * @see     java.io.PrintStream#println(char[])
     148      * @see     java.io.PrintStream#println(double)
     149      * @see     java.io.PrintStream#println(float)
     150      * @see     java.io.PrintStream#println(int)
     151      * @see     java.io.PrintStream#println(long)
     152      * @see     java.io.PrintStream#println(java.lang.Object)
     153      * @see     java.io.PrintStream#println(java.lang.String)
     154      * @see     Console#charset()
     155      * @see     Charset#defaultCharset()
     156      */
     157     public static final PrintStream out = null;
     158
     159     /**
     160      * The "standard" error output stream. This stream is already
     161      * open and ready to accept output data.
     162      * <p>
     163      * Typically this stream corresponds to display output or another
     164      * output destination specified by the host environment or user. By
     165      * convention, this output stream is used to display error messages
     166      * or other information that should come to the immediate attention
     167      * of a user even if the principal output stream, the value of the
     168      * variable {@code out}, has been redirected to a file or other
     169      * destination that is typically not continuously monitored.
     170      * The encoding used in the conversion from characters to bytes is
     171      * equivalent to {@link Console#charset()} if the {@code Console}
     172      * exists, {@link Charset#defaultCharset()} otherwise.
     173      *
     174      * @see     Console#charset()
     175      * @see     Charset#defaultCharset()
     176      */
     177     public static final PrintStream err = null;
     178
     179     // indicates if a security manager is possible
     180     private static final int NEVER = 1;
     181     private static final int MAYBE = 2;
     182     private static @Stable int allowSecurityManager;
     183
     184     // current security manager
     185     private static volatile SecurityManager security;   // read by VM
     186
     187     // return true if a security manager is allowed
     188     private static boolean allowSecurityManager() {
     189         return (allowSecurityManager != NEVER);
     190     }
     191
     192     /**
     193      * Reassigns the "standard" input stream.
     194      *
     195      * First, if there is a security manager, its {@code checkPermission}
     196      * method is called with a {@code RuntimePermission("setIO")} permission
     197      *  to see if it's ok to reassign the "standard" input stream.
     198      *
     199      * @param in the new standard input stream.
     200      *
     201      * @throws SecurityException
     202      *        if a security manager exists and its
     203      *        {@code checkPermission} method doesn't allow
     204      *        reassigning of the standard input stream.
     205      *
     206      * @see SecurityManager#checkPermission
     207      * @see java.lang.RuntimePermission
     208      *
     209      * @since   1.1
     210      */
     211     public static void setIn(InputStream in) {
     212         checkIO();
     213         setIn0(in);
     214     }
     215
     216     /**
     217      * Reassigns the "standard" output stream.
     218      *
     219      * First, if there is a security manager, its {@code checkPermission}
     220      * method is called with a {@code RuntimePermission("setIO")} permission
     221      *  to see if it's ok to reassign the "standard" output stream.
     222      *
     223      * @param out the new standard output stream
     224      *
     225      * @throws SecurityException
     226      *        if a security manager exists and its
     227      *        {@code checkPermission} method doesn't allow
     228      *        reassigning of the standard output stream.
     229      *
     230      * @see SecurityManager#checkPermission
     231      * @see java.lang.RuntimePermission
     232      *
     233      * @since   1.1
     234      */
     235     public static void setOut(PrintStream out) {
     236         checkIO();
     237         setOut0(out);
     238     }
     239
     240     /**
     241      * Reassigns the "standard" error output stream.
     242      *
     243      * First, if there is a security manager, its {@code checkPermission}
     244      * method is called with a {@code RuntimePermission("setIO")} permission
     245      *  to see if it's ok to reassign the "standard" error output stream.
     246      *
     247      * @param err the new standard error output stream.
     248      *
     249      * @throws SecurityException
     250      *        if a security manager exists and its
     251      *        {@code checkPermission} method doesn't allow
     252      *        reassigning of the standard error output stream.
     253      *
     254      * @see SecurityManager#checkPermission
     255      * @see java.lang.RuntimePermission
     256      *
     257      * @since   1.1
     258      */
     259     public static void setErr(PrintStream err) {
     260         checkIO();
     261         setErr0(err);
     262     }
     263
     264     private static volatile Console cons;
     265
     266     /**
     267      * Returns the unique {@link java.io.Console Console} object associated
     268      * with the current Java virtual machine, if any.
     269      *
     270      * @return  The system console, if any, otherwise {@code null}.
     271      *
     272      * @since   1.6
     273      */
     274      public static Console console() {
     275          Console c;
     276          if ((c = cons) == null) {
     277              synchronized (System.class) {
     278                  if ((c = cons) == null) {
     279                      cons = c = SharedSecrets.getJavaIOAccess().console();
     280                  }
     281              }
     282          }
     283          return c;
     284      }
     285
     286     /**
     287      * Returns the channel inherited from the entity that created this
     288      * Java virtual machine.
     289      *
     290      * This method returns the channel obtained by invoking the
     291      * {@link java.nio.channels.spi.SelectorProvider#inheritedChannel
     292      * inheritedChannel} method of the system-wide default
     293      * {@link java.nio.channels.spi.SelectorProvider} object.
     294      *
     295      * <p> In addition to the network-oriented channels described in
     296      * {@link java.nio.channels.spi.SelectorProvider#inheritedChannel
     297      * inheritedChannel}, this method may return other kinds of
     298      * channels in the future.
     299      *
     300      * @return  The inherited channel, if any, otherwise {@code null}.
     301      *
     302      * @throws  IOException
     303      *          If an I/O error occurs
     304      *
     305      * @throws  SecurityException
     306      *          If a security manager is present and it does not
     307      *          permit access to the channel.
     308      *
     309      * @since 1.5
     310      */
     311     public static Channel inheritedChannel() throws IOException {
     312         return SelectorProvider.provider().inheritedChannel();
     313     }
     314
     315     private static void checkIO() {
     316         SecurityManager sm = getSecurityManager();
     317         if (sm != null) {
     318             sm.checkPermission(new RuntimePermission("setIO"));
     319         }
     320     }
     321
     322     private static native void setIn0(InputStream in);
     323     private static native void setOut0(PrintStream out);
     324     private static native void setErr0(PrintStream err);
     325
     326     /**
     327      * Sets the system-wide security manager.
     328      *
     329      * If there is a security manager already installed, this method first
     330      * calls the security manager's {@code checkPermission} method
     331      * with a {@code RuntimePermission("setSecurityManager")}
     332      * permission to ensure it's ok to replace the existing
     333      * security manager.
     334      * This may result in throwing a {@code SecurityException}.
     335      *
     336      * <p> Otherwise, the argument is established as the current
     337      * security manager. If the argument is {@code null} and no
     338      * security manager has been established, then no action is taken and
     339      * the method simply returns.
     340      *
     341      * @implNote In the JDK implementation, if the Java virtual machine is
     342      * started with the system property {@code java.security.manager} set to
     343      * the special token "{@code disallow}" then the {@code setSecurityManager}
     344      * method cannot be used to set a security manager.
     345      *
     346      * @param  sm the security manager or {@code null}
     347      * @throws SecurityException
     348      *         if the security manager has already been set and its {@code
     349      *         checkPermission} method doesn't allow it to be replaced
     350      * @throws UnsupportedOperationException
     351      *         if {@code sm} is non-null and a security manager is not allowed
     352      *         to be set dynamically
     353      * @see #getSecurityManager
     354      * @see SecurityManager#checkPermission
     355      * @see java.lang.RuntimePermission
     356      * @deprecated This method is only useful in conjunction with
     357      *       {@linkplain SecurityManager the Security Manager}, which is
     358      *       deprecated and subject to removal in a future release.
     359      *       Consequently, this method is also deprecated and subject to
     360      *       removal. There is no replacement for the Security Manager or this
     361      *       method.
     362      */
     363     @Deprecated(since="17", forRemoval=true)
     364     public static void setSecurityManager(SecurityManager sm) {
     365         if (allowSecurityManager()) {
     366             if (security == null) {
     367                 // ensure image reader is initialized
     368                 Object.class.getResource("java/lang/ANY");
     369                 // ensure the default file system is initialized
     370                 DefaultFileSystemProvider.theFileSystem();
     371             }
     372             if (sm != null) {
     373                 try {
     374                     // pre-populates the SecurityManager.packageAccess cache
     375                     // to avoid recursive permission checking issues with custom
     376                     // SecurityManager implementations
     377                     sm.checkPackageAccess("java.lang");
     378                 } catch (Exception e) {
     379                     // no-op
     380                 }
     381             }
     382             setSecurityManager0(sm);
     383         } else {
     384             // security manager not allowed
     385             if (sm != null) {
     386                 throw new UnsupportedOperationException(
     387                     "Runtime configured to disallow security manager");
     388             }
     389         }
     390     }
     391
     392     private static synchronized
     393     void setSecurityManager0(final SecurityManager s) {
     394         SecurityManager sm = getSecurityManager();
     395         if (sm != null) {
     396             // ask the currently installed security manager if we
     397             // can replace it.
     398             sm.checkPermission(new RuntimePermission("setSecurityManager"));
     399         }
     400
     401         if ((s != null) && (s.getClass().getClassLoader() != null)) {
     402             // New security manager class is not on bootstrap classpath.
     403             // Force policy to get initialized before we install the new
     404             // security manager, in order to prevent infinite loops when
     405             // trying to initialize the policy (which usually involves
     406             // accessing some security and/or system properties, which in turn
     407             // calls the installed security manager's checkPermission method
     408             // which will loop infinitely if there is a non-system class
     409             // (in this case: the new security manager class) on the stack).
     410             AccessController.doPrivileged(new PrivilegedAction<>() {
     411                 public Object run() {
     412                     s.getClass().getProtectionDomain().implies
     413                         (SecurityConstants.ALL_PERMISSION);
     414                     return null;
     415                 }
     416             });
     417         }
     418
     419         security = s;
     420     }
     421
     422     /**
     423      * Gets the system-wide security manager.
     424      *
     425      * @return  if a security manager has already been established for the
     426      *          current application, then that security manager is returned;
     427      *          otherwise, {@code null} is returned.
     428      * @see     #setSecurityManager
     429      * @deprecated This method is only useful in conjunction with
     430      *       {@linkplain SecurityManager the Security Manager}, which is
     431      *       deprecated and subject to removal in a future release.
     432      *       Consequently, this method is also deprecated and subject to
     433      *       removal. There is no replacement for the Security Manager or this
     434      *       method.
     435      */
     436     @Deprecated(since="17", forRemoval=true)
     437     public static SecurityManager getSecurityManager() {
     438         if (allowSecurityManager()) {
     439             return security;
     440         } else {
     441             return null;
     442         }
     443     }
     444
     445     /**
     446      * Returns the current time in milliseconds.  Note that
     447      * while the unit of time of the return value is a millisecond,
     448      * the granularity of the value depends on the underlying
     449      * operating system and may be larger.  For example, many
     450      * operating systems measure time in units of tens of
     451      * milliseconds.
     452      *
     453      * <p> See the description of the class {@code Date} for
     454      * a discussion of slight discrepancies that may arise between
     455      * "computer time" and coordinated universal time (UTC).
     456      *
     457      * @return  the difference, measured in milliseconds, between
     458      *          the current time and midnight, January 1, 1970 UTC.
     459      * @see     java.util.Date
     460      */
     461     @IntrinsicCandidate
     462     public static native long currentTimeMillis();
     463
     464     /**
     465      * Returns the current value of the running Java Virtual Machine's
     466      * high-resolution time source, in nanoseconds.
     467      *
     468      * This method can only be used to measure elapsed time and is
     469      * not related to any other notion of system or wall-clock time.
     470      * The value returned represents nanoseconds since some fixed but
     471      * arbitrary <i>origin</i> time (perhaps in the future, so values
     472      * may be negative).  The same origin is used by all invocations of
     473      * this method in an instance of a Java virtual machine; other
     474      * virtual machine instances are likely to use a different origin.
     475      *
     476      * <p>This method provides nanosecond precision, but not necessarily
     477      * nanosecond resolution (that is, how frequently the value changes)
     478      * - no guarantees are made except that the resolution is at least as
     479      * good as that of {@link #currentTimeMillis()}.
     480      *
     481      * <p>Differences in successive calls that span greater than
     482      * approximately 292 years (2<sup>63</sup> nanoseconds) will not
     483      * correctly compute elapsed time due to numerical overflow.
     484      *
     485      * <p>The values returned by this method become meaningful only when
     486      * the difference between two such values, obtained within the same
     487      * instance of a Java virtual machine, is computed.
     488      *
     489      * <p>For example, to measure how long some code takes to execute:
     490      * <pre> {@code
     491      * long startTime = System.nanoTime();
     492      * // ... the code being measured ...
     493      * long elapsedNanos = System.nanoTime() - startTime;}</pre>
     494      *
     495      * <p>To compare elapsed time against a timeout, use <pre> {@code
     496      * if (System.nanoTime() - startTime >= timeoutNanos) ...}</pre>
     497      * instead of <pre> {@code
     498      * if (System.nanoTime() >= startTime + timeoutNanos) ...}</pre>
     499      * because of the possibility of numerical overflow.
     500      *
     501      * @return the current value of the running Java Virtual Machine's
     502      *         high-resolution time source, in nanoseconds
     503      * @since 1.5
     504      */
     505     @IntrinsicCandidate
     506     public static native long nanoTime();
     507
     508     /**
     509      * Copies an array from the specified source array, beginning at the
     510      * specified position, to the specified position of the destination array.
     511      * A subsequence of array components are copied from the source
     512      * array referenced by {@code src} to the destination array
     513      * referenced by {@code dest}. The number of components copied is
     514      * equal to the {@code length} argument. The components at
     515      * positions {@code srcPos} through
     516      * {@code srcPos+length-1} in the source array are copied into
     517      * positions {@code destPos} through
     518      * {@code destPos+length-1}, respectively, of the destination
     519      * array.
     520      * <p>
     521      * If the {@code src} and {@code dest} arguments refer to the
     522      * same array object, then the copying is performed as if the
     523      * components at positions {@code srcPos} through
     524      * {@code srcPos+length-1} were first copied to a temporary
     525      * array with {@code length} components and then the contents of
     526      * the temporary array were copied into positions
     527      * {@code destPos} through {@code destPos+length-1} of the
     528      * destination array.
     529      * <p>
     530      * If {@code dest} is {@code null}, then a
     531      * {@code NullPointerException} is thrown.
     532      * <p>
     533      * If {@code src} is {@code null}, then a
     534      * {@code NullPointerException} is thrown and the destination
     535      * array is not modified.
     536      * <p>
     537      * Otherwise, if any of the following is true, an
     538      * {@code ArrayStoreException} is thrown and the destination is
     539      * not modified:
     540      * <ul>
     541      * <li>The {@code src} argument refers to an object that is not an
     542      *     array.
     543      * <li>The {@code dest} argument refers to an object that is not an
     544      *     array.
     545      * <li>The {@code src} argument and {@code dest} argument refer
     546      *     to arrays whose component types are different primitive types.
     547      * <li>The {@code src} argument refers to an array with a primitive
     548      *    component type and the {@code dest} argument refers to an array
     549      *     with a reference component type.
     550      * <li>The {@code src} argument refers to an array with a reference
     551      *    component type and the {@code dest} argument refers to an array
     552      *     with a primitive component type.
     553      * </ul>
     554      * <p>
     555      * Otherwise, if any of the following is true, an
     556      * {@code IndexOutOfBoundsException} is
     557      * thrown and the destination is not modified:
     558      * <ul>
     559      * <li>The {@code srcPos} argument is negative.
     560      * <li>The {@code destPos} argument is negative.
     561      * <li>The {@code length} argument is negative.
     562      * <li>{@code srcPos+length} is greater than
     563      *     {@code src.length}, the length of the source array.
     564      * <li>{@code destPos+length} is greater than
     565      *     {@code dest.length}, the length of the destination array.
     566      * </ul>
     567      * <p>
     568      * Otherwise, if any actual component of the source array from
     569      * position {@code srcPos} through
     570      * {@code srcPos+length-1} cannot be converted to the component
     571      * type of the destination array by assignment conversion, an
     572      * {@code ArrayStoreException} is thrown. In this case, let
     573      * <b><i>k</i></b> be the smallest nonnegative integer less than
     574      * length such that {@code src[srcPos+}<i>k</i>{@code ]}
     575      * cannot be converted to the component type of the destination
     576      * array; when the exception is thrown, source array components from
     577      * positions {@code srcPos} through
     578      * {@code srcPos+}<i>k</i>{@code -1}
     579      * will already have been copied to destination array positions
     580      * {@code destPos} through
     581      * {@code destPos+}<i>k</I>{@code -1} and no other
     582      * positions of the destination array will have been modified.
     583      * (Because of the restrictions already itemized, this
     584      * paragraph effectively applies only to the situation where both
     585      * arrays have component types that are reference types.)
     586      *
     587      * @param      src      the source array.
     588      * @param      srcPos   starting position in the source array.
     589      * @param      dest     the destination array.
     590      * @param      destPos  starting position in the destination data.
     591      * @param      length   the number of array elements to be copied.
     592      * @throws     IndexOutOfBoundsException  if copying would cause
     593      *             access of data outside array bounds.
     594      * @throws     ArrayStoreException  if an element in the {@code src}
     595      *             array could not be stored into the {@code dest} array
     596      *             because of a type mismatch.
     597      * @throws     NullPointerException if either {@code src} or
     598      *             {@code dest} is {@code null}.
     599      */
     600     @IntrinsicCandidate
     601     public static native void arraycopy(Object src,  int  srcPos,
     602                                         Object dest, int destPos,
     603                                         int length);
     604
     605     /**
     606      * Returns the same hash code for the given object as
     607      * would be returned by the default method hashCode(),
     608      * whether or not the given object's class overrides
     609      * hashCode().
     610      * The hash code for the null reference is zero.
     611      *
     612      * @param x object for which the hashCode is to be calculated
     613      * @return  the hashCode
     614      * @since   1.1
     615      * @see Object#hashCode
     616      * @see java.util.Objects#hashCode(Object)
     617      */
     618     @IntrinsicCandidate
     619     public static native int identityHashCode(Object x);
     620
     621     /**
     622      * System properties.
     623      *
     624      * See {@linkplain #getProperties getProperties} for details.
     625      */
     626     private static Properties props;
     627
     628     /**
     629      * Determines the current system properties.
     630      *
     631      * First, if there is a security manager, its
     632      * {@code checkPropertiesAccess} method is called with no
     633      * arguments. This may result in a security exception.
     634      * <p>
     635      * The current set of system properties for use by the
     636      * {@link #getProperty(String)} method is returned as a
     637      * {@code Properties} object. If there is no current set of
     638      * system properties, a set of system properties is first created and
     639      * initialized. This set of system properties includes a value
     640      * for each of the following keys unless the description of the associated
     641      * value indicates that the value is optional.
     642      * <table class="striped" style="text-align:left">
     643      * <caption style="display:none">Shows property keys and associated values</caption>
     644      * <thead>
     645      * <tr><th scope="col">Key</th>
     646      *     <th scope="col">Description of Associated Value</th></tr>
     647      * </thead>
     648      * <tbody>
     649      * <tr><th scope="row">{@systemProperty java.version}</th>
     650      *     <td>Java Runtime Environment version, which may be interpreted
     651      *     as a {@link Runtime.Version}</td></tr>
     652      * <tr><th scope="row">{@systemProperty java.version.date}</th>
     653      *     <td>Java Runtime Environment version date, in ISO-8601 YYYY-MM-DD
     654      *     format, which may be interpreted as a {@link
     655      *     java.time.LocalDate}</td></tr>
     656      * <tr><th scope="row">{@systemProperty java.vendor}</th>
     657      *     <td>Java Runtime Environment vendor</td></tr>
     658      * <tr><th scope="row">{@systemProperty java.vendor.url}</th>
     659      *     <td>Java vendor URL</td></tr>
     660      * <tr><th scope="row">{@systemProperty java.vendor.version}</th>
     661      *     <td>Java vendor version <em>(optional)</em> </td></tr>
     662      * <tr><th scope="row">{@systemProperty java.home}</th>
     663      *     <td>Java installation directory</td></tr>
     664      * <tr><th scope="row">{@systemProperty java.vm.specification.version}</th>
     665      *     <td>Java Virtual Machine specification version, whose value is the
     666      *     {@linkplain Runtime.Version#feature feature} element of the
     667      *     {@linkplain Runtime#version() runtime version}</td></tr>
     668      * <tr><th scope="row">{@systemProperty java.vm.specification.vendor}</th>
     669      *     <td>Java Virtual Machine specification vendor</td></tr>
     670      * <tr><th scope="row">{@systemProperty java.vm.specification.name}</th>
     671      *     <td>Java Virtual Machine specification name</td></tr>
     672      * <tr><th scope="row">{@systemProperty java.vm.version}</th>
     673      *     <td>Java Virtual Machine implementation version which may be
     674      *     interpreted as a {@link Runtime.Version}</td></tr>
     675      * <tr><th scope="row">{@systemProperty java.vm.vendor}</th>
     676      *     <td>Java Virtual Machine implementation vendor</td></tr>
     677      * <tr><th scope="row">{@systemProperty java.vm.name}</th>
     678      *     <td>Java Virtual Machine implementation name</td></tr>
     679      * <tr><th scope="row">{@systemProperty java.specification.version}</th>
     680      *     <td>Java Runtime Environment specification version, whose value is
     681      *     the {@linkplain Runtime.Version#feature feature} element of the
     682      *     {@linkplain Runtime#version() runtime version}</td></tr>
     683      * <tr><th scope="row">{@systemProperty java.specification.vendor}</th>
     684      *     <td>Java Runtime Environment specification  vendor</td></tr>
     685      * <tr><th scope="row">{@systemProperty java.specification.name}</th>
     686      *     <td>Java Runtime Environment specification  name</td></tr>
     687      * <tr><th scope="row">{@systemProperty java.class.version}</th>
     688      *     <td>Java class format version number</td></tr>
     689      * <tr><th scope="row">{@systemProperty java.class.path}</th>
     690      *     <td>Java class path  (refer to
     691      *        {@link ClassLoader#getSystemClassLoader()} for details)</td></tr>
     692      * <tr><th scope="row">{@systemProperty java.library.path}</th>
     693      *     <td>List of paths to search when loading libraries</td></tr>
     694      * <tr><th scope="row">{@systemProperty java.io.tmpdir}</th>
     695      *     <td>Default temp file path</td></tr>
     696      * <tr><th scope="row">{@systemProperty java.compiler}</th>
     697      *     <td>Name of JIT compiler to use</td></tr>
     698      * <tr><th scope="row">{@systemProperty os.name}</th>
     699      *     <td>Operating system name</td></tr>
     700      * <tr><th scope="row">{@systemProperty os.arch}</th>
     701      *     <td>Operating system architecture</td></tr>
     702      * <tr><th scope="row">{@systemProperty os.version}</th>
     703      *     <td>Operating system version</td></tr>
     704      * <tr><th scope="row">{@systemProperty file.separator}</th>
     705      *     <td>File separator ("/" on UNIX)</td></tr>
     706      * <tr><th scope="row">{@systemProperty path.separator}</th>
     707      *     <td>Path separator (":" on UNIX)</td></tr>
     708      * <tr><th scope="row">{@systemProperty line.separator}</th>
     709      *     <td>Line separator ("\n" on UNIX)</td></tr>
     710      * <tr><th scope="row">{@systemProperty user.name}</th>
     711      *     <td>User's account name</td></tr>
     712      * <tr><th scope="row">{@systemProperty user.home}</th>
     713      *     <td>User's home directory</td></tr>
     714      * <tr><th scope="row">{@systemProperty user.dir}</th>
     715      *     <td>User's current working directory</td></tr>
     716      * <tr><th scope="row">{@systemProperty native.encoding}</th>
     717      *     <td>Character encoding name derived from the host environment and/or
     718      *     the user's settings. Setting this system property has no effect.</td></tr>
     719      * </tbody>
     720      * </table>
     721      * <p>
     722      * Multiple paths in a system property value are separated by the path
     723      * separator character of the platform.
     724      * <p>
     725      * Note that even if the security manager does not permit the
     726      * {@code getProperties} operation, it may choose to permit the
     727      * {@link #getProperty(String)} operation.
     728      *
     729      * @apiNote
     730      * <strong>Changing a standard system property may have unpredictable results
     731      * unless otherwise specified.</strong>
     732      * Property values may be cached during initialization or on first use.
     733      * Setting a standard property after initialization using {@link #getProperties()},
     734      * {@link #setProperties(Properties)}, {@link #setProperty(String, String)}, or
     735      * {@link #clearProperty(String)} may not have the desired effect.
     736      *
     737      * @implNote
     738      * In addition to the standard system properties, the system
     739      * properties may include the following keys:
     740      * <table class="striped">
     741      * <caption style="display:none">Shows property keys and associated values</caption>
     742      * <thead>
     743      * <tr><th scope="col">Key</th>
     744      *     <th scope="col">Description of Associated Value</th></tr>
     745      * </thead>
     746      * <tbody>
     747      * <tr><th scope="row">{@systemProperty jdk.module.path}</th>
     748      *     <td>The application module path</td></tr>
     749      * <tr><th scope="row">{@systemProperty jdk.module.upgrade.path}</th>
     750      *     <td>The upgrade module path</td></tr>
     751      * <tr><th scope="row">{@systemProperty jdk.module.main}</th>
     752      *     <td>The module name of the initial/main module</td></tr>
     753      * <tr><th scope="row">{@systemProperty jdk.module.main.class}</th>
     754      *     <td>The main class name of the initial module</td></tr>
     755      * </tbody>
     756      * </table>
     757      *
     758      * @return     the system properties
     759      * @throws     SecurityException  if a security manager exists and its
     760      *             {@code checkPropertiesAccess} method doesn't allow access
     761      *             to the system properties.
     762      * @see        #setProperties
     763      * @see        java.lang.SecurityException
     764      * @see        java.lang.SecurityManager#checkPropertiesAccess()
     765      * @see        java.util.Properties
     766      */
     767     public static Properties getProperties() {
     768         SecurityManager sm = getSecurityManager();
     769         if (sm != null) {
     770             sm.checkPropertiesAccess();
     771         }
     772
     773         return props;
     774     }
     775
     776     /**
     777      * Returns the system-dependent line separator string.  It always
     778      * returns the same value - the initial value of the {@linkplain
     779      * #getProperty(String) system property} {@code line.separator}.
     780      *
     781      * <p>On UNIX systems, it returns {@code "\n"}; on Microsoft
     782      * Windows systems it returns {@code "\r\n"}.
     783      *
     784      * @return the system-dependent line separator string
     785      * @since 1.7
     786      */
     787     public static String lineSeparator() {
     788         return lineSeparator;
     789     }
     790
     791     private static String lineSeparator;
     792
     793     /**
     794      * Sets the system properties to the {@code Properties} argument.
     795      *
     796      * First, if there is a security manager, its
     797      * {@code checkPropertiesAccess} method is called with no
     798      * arguments. This may result in a security exception.
     799      * <p>
     800      * The argument becomes the current set of system properties for use
     801      * by the {@link #getProperty(String)} method. If the argument is
     802      * {@code null}, then the current set of system properties is
     803      * forgotten.
     804      *
     805      * @apiNote
     806      * <strong>Changing a standard system property may have unpredictable results
     807      * unless otherwise specified</strong>.
     808      * See {@linkplain #getProperties getProperties} for details.
     809      *
     810      * @param      props   the new system properties.
     811      * @throws     SecurityException  if a security manager exists and its
     812      *             {@code checkPropertiesAccess} method doesn't allow access
     813      *             to the system properties.
     814      * @see        #getProperties
     815      * @see        java.util.Properties
     816      * @see        java.lang.SecurityException
     817      * @see        java.lang.SecurityManager#checkPropertiesAccess()
     818      */
     819     public static void setProperties(Properties props) {
     820         SecurityManager sm = getSecurityManager();
     821         if (sm != null) {
     822             sm.checkPropertiesAccess();
     823         }
     824
     825         if (props == null) {
     826             Map<String, String> tempProps = SystemProps.initProperties();
     827             VersionProps.init(tempProps);
     828             props = createProperties(tempProps);
     829         }
     830         System.props = props;
     831     }
     832
     833     /**
     834      * Gets the system property indicated by the specified key.
     835      *
     836      * First, if there is a security manager, its
     837      * {@code checkPropertyAccess} method is called with the key as
     838      * its argument. This may result in a SecurityException.
     839      * <p>
     840      * If there is no current set of system properties, a set of system
     841      * properties is first created and initialized in the same manner as
     842      * for the {@code getProperties} method.
     843      *
     844      * @apiNote
     845      * <strong>Changing a standard system property may have unpredictable results
     846      * unless otherwise specified</strong>.
     847      * See {@linkplain #getProperties getProperties} for details.
     848      *
     849      * @param      key   the name of the system property.
     850      * @return     the string value of the system property,
     851      *             or {@code null} if there is no property with that key.
     852      *
     853      * @throws     SecurityException  if a security manager exists and its
     854      *             {@code checkPropertyAccess} method doesn't allow
     855      *             access to the specified system property.
     856      * @throws     NullPointerException if {@code key} is {@code null}.
     857      * @throws     IllegalArgumentException if {@code key} is empty.
     858      * @see        #setProperty
     859      * @see        java.lang.SecurityException
     860      * @see        java.lang.SecurityManager#checkPropertyAccess(java.lang.String)
     861      * @see        java.lang.System#getProperties()
     862      */
     863     public static String getProperty(String key) {
     864         checkKey(key);
     865         SecurityManager sm = getSecurityManager();
     866         if (sm != null) {
     867             sm.checkPropertyAccess(key);
     868         }
     869
     870         return props.getProperty(key);
     871     }
     872
     873     /**
     874      * Gets the system property indicated by the specified key.
     875      *
     876      * First, if there is a security manager, its
     877      * {@code checkPropertyAccess} method is called with the
     878      * {@code key} as its argument.
     879      * <p>
     880      * If there is no current set of system properties, a set of system
     881      * properties is first created and initialized in the same manner as
     882      * for the {@code getProperties} method.
     883      *
     884      * @param      key   the name of the system property.
     885      * @param      def   a default value.
     886      * @return     the string value of the system property,
     887      *             or the default value if there is no property with that key.
     888      *
     889      * @throws     SecurityException  if a security manager exists and its
     890      *             {@code checkPropertyAccess} method doesn't allow
     891      *             access to the specified system property.
     892      * @throws     NullPointerException if {@code key} is {@code null}.
     893      * @throws     IllegalArgumentException if {@code key} is empty.
     894      * @see        #setProperty
     895      * @see        java.lang.SecurityManager#checkPropertyAccess(java.lang.String)
     896      * @see        java.lang.System#getProperties()
     897      */
     898     public static String getProperty(String key, String def) {
     899         checkKey(key);
     900         SecurityManager sm = getSecurityManager();
     901         if (sm != null) {
     902             sm.checkPropertyAccess(key);
     903         }
     904
     905         return props.getProperty(key, def);
     906     }
     907
     908     /**
     909      * Sets the system property indicated by the specified key.
     910      *
     911      * First, if a security manager exists, its
     912      * {@code SecurityManager.checkPermission} method
     913      * is called with a {@code PropertyPermission(key, "write")}
     914      * permission. This may result in a SecurityException being thrown.
     915      * If no exception is thrown, the specified property is set to the given
     916      * value.
     917      *
     918      * @apiNote
     919      * <strong>Changing a standard system property may have unpredictable results
     920      * unless otherwise specified</strong>.
     921      * See {@linkplain #getProperties getProperties} for details.
     922      *
     923      * @param      key   the name of the system property.
     924      * @param      value the value of the system property.
     925      * @return     the previous value of the system property,
     926      *             or {@code null} if it did not have one.
     927      *
     928      * @throws     SecurityException  if a security manager exists and its
     929      *             {@code checkPermission} method doesn't allow
     930      *             setting of the specified property.
     931      * @throws     NullPointerException if {@code key} or
     932      *             {@code value} is {@code null}.
     933      * @throws     IllegalArgumentException if {@code key} is empty.
     934      * @see        #getProperty
     935      * @see        java.lang.System#getProperty(java.lang.String)
     936      * @see        java.lang.System#getProperty(java.lang.String, java.lang.String)
     937      * @see        java.util.PropertyPermission
     938      * @see        SecurityManager#checkPermission
     939      * @since      1.2
     940      */
     941     public static String setProperty(String key, String value) {
     942         checkKey(key);
     943         SecurityManager sm = getSecurityManager();
     944         if (sm != null) {
     945             sm.checkPermission(new PropertyPermission(key,
     946                 SecurityConstants.PROPERTY_WRITE_ACTION));
     947         }
     948
     949         return (String) props.setProperty(key, value);
     950     }
     951
     952     /**
     953      * Removes the system property indicated by the specified key.
     954      *
     955      * First, if a security manager exists, its
     956      * {@code SecurityManager.checkPermission} method
     957      * is called with a {@code PropertyPermission(key, "write")}
     958      * permission. This may result in a SecurityException being thrown.
     959      * If no exception is thrown, the specified property is removed.
     960      *
     961      * @apiNote
     962      * <strong>Changing a standard system property may have unpredictable results
     963      * unless otherwise specified</strong>.
     964      * See {@linkplain #getProperties getProperties} method for details.
     965      *
     966      * @param      key   the name of the system property to be removed.
     967      * @return     the previous string value of the system property,
     968      *             or {@code null} if there was no property with that key.
     969      *
     970      * @throws     SecurityException  if a security manager exists and its
     971      *             {@code checkPropertyAccess} method doesn't allow
     972      *              access to the specified system property.
     973      * @throws     NullPointerException if {@code key} is {@code null}.
     974      * @throws     IllegalArgumentException if {@code key} is empty.
     975      * @see        #getProperty
     976      * @see        #setProperty
     977      * @see        java.util.Properties
     978      * @see        java.lang.SecurityException
     979      * @see        java.lang.SecurityManager#checkPropertiesAccess()
     980      * @since 1.5
     981      */
     982     public static String clearProperty(String key) {
     983         checkKey(key);
     984         SecurityManager sm = getSecurityManager();
     985         if (sm != null) {
     986             sm.checkPermission(new PropertyPermission(key, "write"));
     987         }
     988
     989         return (String) props.remove(key);
     990     }
     991
     992     private static void checkKey(String key) {
     993         if (key == null) {
     994             throw new NullPointerException("key can't be null");
     995         }
     996         if (key.isEmpty()) {
     997             throw new IllegalArgumentException("key can't be empty");
     998         }
     999     }
    1000
    1001     /**
    1002      * Gets the value of the specified environment variable. An
    1003      * environment variable is a system-dependent external named
    1004      * value.
    1005      *
    1006      * <p>If a security manager exists, its
    1007      * {@link SecurityManager#checkPermission checkPermission}
    1008      * method is called with a
    1009      * {@link RuntimePermission RuntimePermission("getenv."+name)}
    1010      * permission.  This may result in a {@link SecurityException}
    1011      * being thrown.  If no exception is thrown the value of the
    1012      * variable {@code name} is returned.
    1013      *
    1014      * <p><a id="EnvironmentVSSystemProperties"><i>System
    1015      * properties</i> and <i>environment variables</i></a> are both
    1016      * conceptually mappings between names and values.  Both
    1017      * mechanisms can be used to pass user-defined information to a
    1018      * Java process.  Environment variables have a more global effect,
    1019      * because they are visible to all descendants of the process
    1020      * which defines them, not just the immediate Java subprocess.
    1021      * They can have subtly different semantics, such as case
    1022      * insensitivity, on different operating systems.  For these
    1023      * reasons, environment variables are more likely to have
    1024      * unintended side effects.  It is best to use system properties
    1025      * where possible.  Environment variables should be used when a
    1026      * global effect is desired, or when an external system interface
    1027      * requires an environment variable (such as {@code PATH}).
    1028      *
    1029      * <p>On UNIX systems the alphabetic case of {@code name} is
    1030      * typically significant, while on Microsoft Windows systems it is
    1031      * typically not.  For example, the expression
    1032      * {@code System.getenv("FOO").equals(System.getenv("foo"))}
    1033      * is likely to be true on Microsoft Windows.
    1034      *
    1035      * @param  name the name of the environment variable
    1036      * @return the string value of the variable, or {@code null}
    1037      *         if the variable is not defined in the system environment
    1038      * @throws NullPointerException if {@code name} is {@code null}
    1039      * @throws SecurityException
    1040      *         if a security manager exists and its
    1041      *         {@link SecurityManager#checkPermission checkPermission}
    1042      *         method doesn't allow access to the environment variable
    1043      *         {@code name}
    1044      * @see    #getenv()
    1045      * @see    ProcessBuilder#environment()
    1046      */
    1047     public static String getenv(String name) {
    1048         SecurityManager sm = getSecurityManager();
    1049         if (sm != null) {
    1050             sm.checkPermission(new RuntimePermission("getenv."+name));
    1051         }
    1052
    1053         return ProcessEnvironment.getenv(name);
    1054     }
    1055
    1056
    1057     /**
    1058      * Returns an unmodifiable string map view of the current system environment.
    1059      * The environment is a system-dependent mapping from names to
    1060      * values which is passed from parent to child processes.
    1061      *
    1062      * <p>If the system does not support environment variables, an
    1063      * empty map is returned.
    1064      *
    1065      * <p>The returned map will never contain null keys or values.
    1066      * Attempting to query the presence of a null key or value will
    1067      * throw a {@link NullPointerException}.  Attempting to query
    1068      * the presence of a key or value which is not of type
    1069      * {@link String} will throw a {@link ClassCastException}.
    1070      *
    1071      * <p>The returned map and its collection views may not obey the
    1072      * general contract of the {@link Object#equals} and
    1073      * {@link Object#hashCode} methods.
    1074      *
    1075      * <p>The returned map is typically case-sensitive on all platforms.
    1076      *
    1077      * <p>If a security manager exists, its
    1078      * {@link SecurityManager#checkPermission checkPermission}
    1079      * method is called with a
    1080      * {@link RuntimePermission RuntimePermission("getenv.*")} permission.
    1081      * This may result in a {@link SecurityException} being thrown.
    1082      *
    1083      * <p>When passing information to a Java subprocess,
    1084      * <a href=#EnvironmentVSSystemProperties>system properties</a>
    1085      * are generally preferred over environment variables.
    1086      *
    1087      * @return the environment as a map of variable names to values
    1088      * @throws SecurityException
    1089      *         if a security manager exists and its
    1090      *         {@link SecurityManager#checkPermission checkPermission}
    1091      *         method doesn't allow access to the process environment
    1092      * @see    #getenv(String)
    1093      * @see    ProcessBuilder#environment()
    1094      * @since  1.5
    1095      */
    1096     public static java.util.Map<String,String> getenv() {
    1097         SecurityManager sm = getSecurityManager();
    1098         if (sm != null) {
    1099             sm.checkPermission(new RuntimePermission("getenv.*"));
    1100         }
    1101
    1102         return ProcessEnvironment.getenv();
    1103     }
    1104
    1105     /**
    1106      * {@code System.Logger} instances log messages that will be
    1107      * routed to the underlying logging framework the {@link System.LoggerFinder
    1108      * LoggerFinder} uses.
    1109      *
    1110      * {@code System.Logger} instances are typically obtained from
    1111      * the {@link java.lang.System System} class, by calling
    1112      * {@link java.lang.System#getLogger(java.lang.String) System.getLogger(loggerName)}
    1113      * or {@link java.lang.System#getLogger(java.lang.String, java.util.ResourceBundle)
    1114      * System.getLogger(loggerName, bundle)}.
    1115      *
    1116      * @see java.lang.System#getLogger(java.lang.String)
    1117      * @see java.lang.System#getLogger(java.lang.String, java.util.ResourceBundle)
    1118      * @see java.lang.System.LoggerFinder
    1119      *
    1120      * @since 9
    1121      */
    1122     public interface Logger {
    1123
    1124         /**
    1125          * System {@linkplain Logger loggers} levels.
    1126          *
    1127          * A level has a {@linkplain #getName() name} and {@linkplain
    1128          * #getSeverity() severity}.
    1129          * Level values are {@link #ALL}, {@link #TRACE}, {@link #DEBUG},
    1130          * {@link #INFO}, {@link #WARNING}, {@link #ERROR}, {@link #OFF},
    1131          * by order of increasing severity.
    1132          * <br>
    1133          * {@link #ALL} and {@link #OFF}
    1134          * are simple markers with severities mapped respectively to
    1135          * {@link java.lang.Integer#MIN_VALUE Integer.MIN_VALUE} and
    1136          * {@link java.lang.Integer#MAX_VALUE Integer.MAX_VALUE}.
    1137          * <p>
    1138          * <b>Severity values and Mapping to {@code java.util.logging.Level}.</b>
    1139          * <p>
    1140          * {@linkplain System.Logger.Level System logger levels} are mapped to
    1141          * {@linkplain java.util.logging.Level  java.util.logging levels}
    1142          * of corresponding severity.
    1143          * <br>The mapping is as follows:
    1144          * <br><br>
    1145          * <table class="striped">
    1146          * <caption>System.Logger Severity Level Mapping</caption>
    1147          * <thead>
    1148          * <tr><th scope="col">System.Logger Levels</th>
    1149          *     <th scope="col">java.util.logging Levels</th>
    1150          * </thead>
    1151          * <tbody>
    1152          * <tr><th scope="row">{@link Logger.Level#ALL ALL}</th>
    1153          *     <td>{@link java.util.logging.Level#ALL ALL}</td>
    1154          * <tr><th scope="row">{@link Logger.Level#TRACE TRACE}</th>
    1155          *     <td>{@link java.util.logging.Level#FINER FINER}</td>
    1156          * <tr><th scope="row">{@link Logger.Level#DEBUG DEBUG}</th>
    1157          *     <td>{@link java.util.logging.Level#FINE FINE}</td>
    1158          * <tr><th scope="row">{@link Logger.Level#INFO INFO}</th>
    1159          *     <td>{@link java.util.logging.Level#INFO INFO}</td>
    1160          * <tr><th scope="row">{@link Logger.Level#WARNING WARNING}</th>
    1161          *     <td>{@link java.util.logging.Level#WARNING WARNING}</td>
    1162          * <tr><th scope="row">{@link Logger.Level#ERROR ERROR}</th>
    1163          *     <td>{@link java.util.logging.Level#SEVERE SEVERE}</td>
    1164          * <tr><th scope="row">{@link Logger.Level#OFF OFF}</th>
    1165          *     <td>{@link java.util.logging.Level#OFF OFF}</td>
    1166          * </tbody>
    1167          * </table>
    1168          *
    1169          * @since 9
    1170          *
    1171          * @see java.lang.System.LoggerFinder
    1172          * @see java.lang.System.Logger
    1173          */
    1174         public enum Level {
    1175
    1176             // for convenience, we're reusing java.util.logging.Level int values
    1177             // the mapping logic in sun.util.logging.PlatformLogger depends
    1178             // on this.
    1179             /**
    1180              * A marker to indicate that all levels are enabled.
    1181              * This level {@linkplain #getSeverity() severity} is
    1182              * {@link Integer#MIN_VALUE}.
    1183              */
    1184             ALL(Integer.MIN_VALUE),  // typically mapped to/from j.u.l.Level.ALL
    1185             /**
    1186              * {@code TRACE} level: usually used to log diagnostic information.
    1187              * This level {@linkplain #getSeverity() severity} is
    1188              * {@code 400}.
    1189              */
    1190             TRACE(400),   // typically mapped to/from j.u.l.Level.FINER
    1191             /**
    1192              * {@code DEBUG} level: usually used to log debug information traces.
    1193              * This level {@linkplain #getSeverity() severity} is
    1194              * {@code 500}.
    1195              */
    1196             DEBUG(500),   // typically mapped to/from j.u.l.Level.FINEST/FINE/CONFIG
    1197             /**
    1198              * {@code INFO} level: usually used to log information messages.
    1199              * This level {@linkplain #getSeverity() severity} is
    1200              * {@code 800}.
    1201              */
    1202             INFO(800),    // typically mapped to/from j.u.l.Level.INFO
    1203             /**
    1204              * {@code WARNING} level: usually used to log warning messages.
    1205              * This level {@linkplain #getSeverity() severity} is
    1206              * {@code 900}.
    1207              */
    1208             WARNING(900), // typically mapped to/from j.u.l.Level.WARNING
    1209             /**
    1210              * {@code ERROR} level: usually used to log error messages.
    1211              * This level {@linkplain #getSeverity() severity} is
    1212              * {@code 1000}.
    1213              */
    1214             ERROR(1000),  // typically mapped to/from j.u.l.Level.SEVERE
    1215             /**
    1216              * A marker to indicate that all levels are disabled.
    1217              * This level {@linkplain #getSeverity() severity} is
    1218              * {@link Integer#MAX_VALUE}.
    1219              */
    1220             OFF(Integer.MAX_VALUE);  // typically mapped to/from j.u.l.Level.OFF
    1221
    1222             private final int severity;
    1223
    1224             private Level(int severity) {
    1225                 this.severity = severity;
    1226             }
    1227
    1228             /**
    1229              * Returns the name of this level.
    1230              * @return this level {@linkplain #name()}.
    1231              */
    1232             public final String getName() {
    1233                 return name();
    1234             }
    1235
    1236             /**
    1237              * Returns the severity of this level.
    1238              * A higher severity means a more severe condition.
    1239              * @return this level severity.
    1240              */
    1241             public final int getSeverity() {
    1242                 return severity;
    1243             }
    1244         }
    1245
    1246         /**
    1247          * Returns the name of this logger.
    1248          *
    1249          * @return the logger name.
    1250          */
    1251         public String getName();
    1252
    1253         /**
    1254          * Checks if a message of the given level would be logged by
    1255          * this logger.
    1256          *
    1257          * @param level the log message level.
    1258          * @return {@code true} if the given log message level is currently
    1259          *         being logged.
    1260          *
    1261          * @throws NullPointerException if {@code level} is {@code null}.
    1262          */
    1263         public boolean isLoggable(Level level);
    1264
    1265         /**
    1266          * Logs a message.
    1267          *
    1268          * @implSpec The default implementation for this method calls
    1269          * {@code this.log(level, (ResourceBundle)null, msg, (Object[])null);}
    1270          *
    1271          * @param level the log message level.
    1272          * @param msg the string message (or a key in the message catalog, if
    1273          * this logger is a {@link
    1274          * LoggerFinder#getLocalizedLogger(java.lang.String,
    1275          * java.util.ResourceBundle, java.lang.Module) localized logger});
    1276          * can be {@code null}.
    1277          *
    1278          * @throws NullPointerException if {@code level} is {@code null}.
    1279          */
    1280         public default void log(Level level, String msg) {
    1281             log(level, (ResourceBundle) null, msg, (Object[]) null);
    1282         }
    1283
    1284         /**
    1285          * Logs a lazily supplied message.
    1286          *
    1287          * If the logger is currently enabled for the given log message level
    1288          * then a message is logged that is the result produced by the
    1289          * given supplier function.  Otherwise, the supplier is not operated on.
    1290          *
    1291          * @implSpec When logging is enabled for the given level, the default
    1292          * implementation for this method calls
    1293          * {@code this.log(level, (ResourceBundle)null, msgSupplier.get(), (Object[])null);}
    1294          *
    1295          * @param level the log message level.
    1296          * @param msgSupplier a supplier function that produces a message.
    1297          *
    1298          * @throws NullPointerException if {@code level} is {@code null},
    1299          *         or {@code msgSupplier} is {@code null}.
    1300          */
    1301         public default void log(Level level, Supplier<String> msgSupplier) {
    1302             Objects.requireNonNull(msgSupplier);
    1303             if (isLoggable(Objects.requireNonNull(level))) {
    1304                 log(level, (ResourceBundle) null, msgSupplier.get(), (Object[]) null);
    1305             }
    1306         }
    1307
    1308         /**
    1309          * Logs a message produced from the given object.
    1310          *
    1311          * If the logger is currently enabled for the given log message level then
    1312          * a message is logged that, by default, is the result produced from
    1313          * calling  toString on the given object.
    1314          * Otherwise, the object is not operated on.
    1315          *
    1316          * @implSpec When logging is enabled for the given level, the default
    1317          * implementation for this method calls
    1318          * {@code this.log(level, (ResourceBundle)null, obj.toString(), (Object[])null);}
    1319          *
    1320          * @param level the log message level.
    1321          * @param obj the object to log.
    1322          *
    1323          * @throws NullPointerException if {@code level} is {@code null}, or
    1324          *         {@code obj} is {@code null}.
    1325          */
    1326         public default void log(Level level, Object obj) {
    1327             Objects.requireNonNull(obj);
    1328             if (isLoggable(Objects.requireNonNull(level))) {
    1329                 this.log(level, (ResourceBundle) null, obj.toString(), (Object[]) null);
    1330             }
    1331         }
    1332
    1333         /**
    1334          * Logs a message associated with a given throwable.
    1335          *
    1336          * @implSpec The default implementation for this method calls
    1337          * {@code this.log(level, (ResourceBundle)null, msg, thrown);}
    1338          *
    1339          * @param level the log message level.
    1340          * @param msg the string message (or a key in the message catalog, if
    1341          * this logger is a {@link
    1342          * LoggerFinder#getLocalizedLogger(java.lang.String,
    1343          * java.util.ResourceBundle, java.lang.Module) localized logger});
    1344          * can be {@code null}.
    1345          * @param thrown a {@code Throwable} associated with the log message;
    1346          *        can be {@code null}.
    1347          *
    1348          * @throws NullPointerException if {@code level} is {@code null}.
    1349          */
    1350         public default void log(Level level, String msg, Throwable thrown) {
    1351             this.log(level, null, msg, thrown);
    1352         }
    1353
    1354         /**
    1355          * Logs a lazily supplied message associated with a given throwable.
    1356          *
    1357          * If the logger is currently enabled for the given log message level
    1358          * then a message is logged that is the result produced by the
    1359          * given supplier function.  Otherwise, the supplier is not operated on.
    1360          *
    1361          * @implSpec When logging is enabled for the given level, the default
    1362          * implementation for this method calls
    1363          * {@code this.log(level, (ResourceBundle)null, msgSupplier.get(), thrown);}
    1364          *
    1365          * @param level one of the log message level identifiers.
    1366          * @param msgSupplier a supplier function that produces a message.
    1367          * @param thrown a {@code Throwable} associated with log message;
    1368          *               can be {@code null}.
    1369          *
    1370          * @throws NullPointerException if {@code level} is {@code null}, or
    1371          *                               {@code msgSupplier} is {@code null}.
    1372          */
    1373         public default void log(Level level, Supplier<String> msgSupplier,
    1374                 Throwable thrown) {
    1375             Objects.requireNonNull(msgSupplier);
    1376             if (isLoggable(Objects.requireNonNull(level))) {
    1377                 this.log(level, null, msgSupplier.get(), thrown);
    1378             }
    1379         }
    1380
    1381         /**
    1382          * Logs a message with an optional list of parameters.
    1383          *
    1384          * @implSpec The default implementation for this method calls
    1385          * {@code this.log(level, (ResourceBundle)null, format, params);}
    1386          *
    1387          * @param level one of the log message level identifiers.
    1388          * @param format the string message format in {@link
    1389          * java.text.MessageFormat} format, (or a key in the message
    1390          * catalog, if this logger is a {@link
    1391          * LoggerFinder#getLocalizedLogger(java.lang.String,
    1392          * java.util.ResourceBundle, java.lang.Module) localized logger});
    1393          * can be {@code null}.
    1394          * @param params an optional list of parameters to the message (may be
    1395          * none).
    1396          *
    1397          * @throws NullPointerException if {@code level} is {@code null}.
    1398          */
    1399         public default void log(Level level, String format, Object... params) {
    1400             this.log(level, null, format, params);
    1401         }
    1402
    1403         /**
    1404          * Logs a localized message associated with a given throwable.
    1405          *
    1406          * If the given resource bundle is non-{@code null},  the {@code msg}
    1407          * string is localized using the given resource bundle.
    1408          * Otherwise the {@code msg} string is not localized.
    1409          *
    1410          * @param level the log message level.
    1411          * @param bundle a resource bundle to localize {@code msg}; can be
    1412          * {@code null}.
    1413          * @param msg the string message (or a key in the message catalog,
    1414          *            if {@code bundle} is not {@code null}); can be {@code null}.
    1415          * @param thrown a {@code Throwable} associated with the log message;
    1416          *        can be {@code null}.
    1417          *
    1418          * @throws NullPointerException if {@code level} is {@code null}.
    1419          */
    1420         public void log(Level level, ResourceBundle bundle, String msg,
    1421                 Throwable thrown);
    1422
    1423         /**
    1424          * Logs a message with resource bundle and an optional list of
    1425          * parameters.
    1426          *
    1427          * If the given resource bundle is non-{@code null},  the {@code format}
    1428          * string is localized using the given resource bundle.
    1429          * Otherwise the {@code format} string is not localized.
    1430          *
    1431          * @param level the log message level.
    1432          * @param bundle a resource bundle to localize {@code format}; can be
    1433          * {@code null}.
    1434          * @param format the string message format in {@link
    1435          * java.text.MessageFormat} format, (or a key in the message
    1436          * catalog if {@code bundle} is not {@code null}); can be {@code null}.
    1437          * @param params an optional list of parameters to the message (may be
    1438          * none).
    1439          *
    1440          * @throws NullPointerException if {@code level} is {@code null}.
    1441          */
    1442         public void log(Level level, ResourceBundle bundle, String format,
    1443                 Object... params);
    1444     }
    1445
    1446     /**
    1447      * The {@code LoggerFinder} service is responsible for creating, managing,
    1448      * and configuring loggers to the underlying framework it uses.
    1449      *
    1450      * A logger finder is a concrete implementation of this class that has a
    1451      * zero-argument constructor and implements the abstract methods defined
    1452      * by this class.
    1453      * The loggers returned from a logger finder are capable of routing log
    1454      * messages to the logging backend this provider supports.
    1455      * A given invocation of the Java Runtime maintains a single
    1456      * system-wide LoggerFinder instance that is loaded as follows:
    1457      * <ul>
    1458      *    <li>First it finds any custom {@code LoggerFinder} provider
    1459      *        using the {@link java.util.ServiceLoader} facility with the
    1460      *        {@linkplain ClassLoader#getSystemClassLoader() system class
    1461      *        loader}.</li>
    1462      *    <li>If no {@code LoggerFinder} provider is found, the system default
    1463      *        {@code LoggerFinder} implementation will be used.</li>
    1464      * </ul>
    1465      * <p>
    1466      * An application can replace the logging backend
    1467      * <i>even when the java.logging module is present</i>, by simply providing
    1468      * and declaring an implementation of the {@link LoggerFinder} service.
    1469      * <p>
    1470      * <b>Default Implementation</b>
    1471      * <p>
    1472      * The system default {@code LoggerFinder} implementation uses
    1473      * {@code java.util.logging} as the backend framework when the
    1474      * {@code java.logging} module is present.
    1475      * It returns a {@linkplain System.Logger logger} instance
    1476      * that will route log messages to a {@link java.util.logging.Logger
    1477      * java.util.logging.Logger}. Otherwise, if {@code java.logging} is not
    1478      * present, the default implementation will return a simple logger
    1479      * instance that will route log messages of {@code INFO} level and above to
    1480      * the console ({@code System.err}).
    1481      * <p>
    1482      * <b>Logging Configuration</b>
    1483      * <p>
    1484      * {@linkplain Logger Logger} instances obtained from the
    1485      * {@code LoggerFinder} factory methods are not directly configurable by
    1486      * the application. Configuration is the responsibility of the underlying
    1487      * logging backend, and usually requires using APIs specific to that backend.
    1488      * <p>For the default {@code LoggerFinder} implementation
    1489      * using {@code java.util.logging} as its backend, refer to
    1490      * {@link java.util.logging java.util.logging} for logging configuration.
    1491      * For the default {@code LoggerFinder} implementation returning simple loggers
    1492      * when the {@code java.logging} module is absent, the configuration
    1493      * is implementation dependent.
    1494      * <p>
    1495      * Usually an application that uses a logging framework will log messages
    1496      * through a logger facade defined (or supported) by that framework.
    1497      * Applications that wish to use an external framework should log
    1498      * through the facade associated with that framework.
    1499      * <p>
    1500      * A system class that needs to log messages will typically obtain
    1501      * a {@link System.Logger} instance to route messages to the logging
    1502      * framework selected by the application.
    1503      * <p>
    1504      * Libraries and classes that only need loggers to produce log messages
    1505      * should not attempt to configure loggers by themselves, as that
    1506      * would make them dependent from a specific implementation of the
    1507      * {@code LoggerFinder} service.
    1508      * <p>
    1509      * In addition, when a security manager is present, loggers provided to
    1510      * system classes should not be directly configurable through the logging
    1511      * backend without requiring permissions.
    1512      * <br>
    1513      * It is the responsibility of the provider of
    1514      * the concrete {@code LoggerFinder} implementation to ensure that
    1515      * these loggers are not configured by untrusted code without proper
    1516      * permission checks, as configuration performed on such loggers usually
    1517      * affects all applications in the same Java Runtime.
    1518      * <p>
    1519      * <b>Message Levels and Mapping to backend levels</b>
    1520      * <p>
    1521      * A logger finder is responsible for mapping from a {@code
    1522      * System.Logger.Level} to a level supported by the logging backend it uses.
    1523      * <br>The default LoggerFinder using {@code java.util.logging} as the backend
    1524      * maps {@code System.Logger} levels to
    1525      * {@linkplain java.util.logging.Level java.util.logging} levels
    1526      * of corresponding severity - as described in {@link Logger.Level
    1527      * Logger.Level}.
    1528      *
    1529      * @see java.lang.System
    1530      * @see java.lang.System.Logger
    1531      *
    1532      * @since 9
    1533      */
    1534     public static abstract class LoggerFinder {
    1535         /**
    1536          * The {@code RuntimePermission("loggerFinder")} is
    1537          * necessary to subclass and instantiate the {@code LoggerFinder} class,
    1538          * as well as to obtain loggers from an instance of that class.
    1539          */
    1540         static final RuntimePermission LOGGERFINDER_PERMISSION =
    1541                 new RuntimePermission("loggerFinder");
    1542
    1543         /**
    1544          * Creates a new instance of {@code LoggerFinder}.
    1545          *
    1546          * @implNote It is recommended that a {@code LoggerFinder} service
    1547          *   implementation does not perform any heavy initialization in its
    1548          *   constructor, in order to avoid possible risks of deadlock or class
    1549          *   loading cycles during the instantiation of the service provider.
    1550          *
    1551          * @throws SecurityException if a security manager is present and its
    1552          *         {@code checkPermission} method doesn't allow the
    1553          *         {@code RuntimePermission("loggerFinder")}.
    1554          */
    1555         protected LoggerFinder() {
    1556             this(checkPermission());
    1557         }
    1558
    1559         private LoggerFinder(Void unused) {
    1560             // nothing to do.
    1561         }
    1562
    1563         private static Void checkPermission() {
    1564             final SecurityManager sm = System.getSecurityManager();
    1565             if (sm != null) {
    1566                 sm.checkPermission(LOGGERFINDER_PERMISSION);
    1567             }
    1568             return null;
    1569         }
    1570
    1571         /**
    1572          * Returns an instance of {@link Logger Logger}
    1573          * for the given {@code module}.
    1574          *
    1575          * @param name the name of the logger.
    1576          * @param module the module for which the logger is being requested.
    1577          *
    1578          * @return a {@link Logger logger} suitable for use within the given
    1579          *         module.
    1580          * @throws NullPointerException if {@code name} is {@code null} or
    1581          *        {@code module} is {@code null}.
    1582          * @throws SecurityException if a security manager is present and its
    1583          *         {@code checkPermission} method doesn't allow the
    1584          *         {@code RuntimePermission("loggerFinder")}.
    1585          */
    1586         public abstract Logger getLogger(String name, Module module);
    1587
    1588         /**
    1589          * Returns a localizable instance of {@link Logger Logger}
    1590          * for the given {@code module}.
    1591          * The returned logger will use the provided resource bundle for
    1592          * message localization.
    1593          *
    1594          * @implSpec By default, this method calls {@link
    1595          * #getLogger(java.lang.String, java.lang.Module)
    1596          * this.getLogger(name, module)} to obtain a logger, then wraps that
    1597          * logger in a {@link Logger} instance where all methods that do not
    1598          * take a {@link ResourceBundle} as parameter are redirected to one
    1599          * which does - passing the given {@code bundle} for
    1600          * localization. So for instance, a call to {@link
    1601          * Logger#log(Logger.Level, String) Logger.log(Level.INFO, msg)}
    1602          * will end up as a call to {@link
    1603          * Logger#log(Logger.Level, ResourceBundle, String, Object...)
    1604          * Logger.log(Level.INFO, bundle, msg, (Object[])null)} on the wrapped
    1605          * logger instance.
    1606          * Note however that by default, string messages returned by {@link
    1607          * java.util.function.Supplier Supplier&lt;String&gt;} will not be
    1608          * localized, as it is assumed that such strings are messages which are
    1609          * already constructed, rather than keys in a resource bundle.
    1610          * <p>
    1611          * An implementation of {@code LoggerFinder} may override this method,
    1612          * for example, when the underlying logging backend provides its own
    1613          * mechanism for localizing log messages, then such a
    1614          * {@code LoggerFinder} would be free to return a logger
    1615          * that makes direct use of the mechanism provided by the backend.
    1616          *
    1617          * @param name    the name of the logger.
    1618          * @param bundle  a resource bundle; can be {@code null}.
    1619          * @param module  the module for which the logger is being requested.
    1620          * @return an instance of {@link Logger Logger}  which will use the
    1621          * provided resource bundle for message localization.
    1622          *
    1623          * @throws NullPointerException if {@code name} is {@code null} or
    1624          *         {@code module} is {@code null}.
    1625          * @throws SecurityException if a security manager is present and its
    1626          *         {@code checkPermission} method doesn't allow the
    1627          *         {@code RuntimePermission("loggerFinder")}.
    1628          */
    1629         public Logger getLocalizedLogger(String name, ResourceBundle bundle,
    1630                                          Module module) {
    1631             return new LocalizedLoggerWrapper<>(getLogger(name, module), bundle);
    1632         }
    1633
    1634         /**
    1635          * Returns the {@code LoggerFinder} instance. There is one
    1636          * single system-wide {@code LoggerFinder} instance in
    1637          * the Java Runtime.  See the class specification of how the
    1638          * {@link LoggerFinder LoggerFinder} implementation is located and
    1639          * loaded.
    1640          *
    1641          * @return the {@link LoggerFinder LoggerFinder} instance.
    1642          * @throws SecurityException if a security manager is present and its
    1643          *         {@code checkPermission} method doesn't allow the
    1644          *         {@code RuntimePermission("loggerFinder")}.
    1645          */
    1646         public static LoggerFinder getLoggerFinder() {
    1647             final SecurityManager sm = System.getSecurityManager();
    1648             if (sm != null) {
    1649                 sm.checkPermission(LOGGERFINDER_PERMISSION);
    1650             }
    1651             return accessProvider();
    1652         }
    1653
    1654
    1655         private static volatile LoggerFinder service;
    1656         static LoggerFinder accessProvider() {
    1657             // We do not need to synchronize: LoggerFinderLoader will
    1658             // always return the same instance, so if we don't have it,
    1659             // just fetch it again.
    1660             if (service == null) {
    1661                 PrivilegedAction<LoggerFinder> pa =
    1662                         () -> LoggerFinderLoader.getLoggerFinder();
    1663                 service = AccessController.doPrivileged(pa, null,
    1664                         LOGGERFINDER_PERMISSION);
    1665             }
    1666             return service;
    1667         }
    1668
    1669     }
    1670
    1671
    1672     /**
    1673      * Returns an instance of {@link Logger Logger} for the caller's
    1674      * use.
    1675      *
    1676      * @implSpec
    1677      * Instances returned by this method route messages to loggers
    1678      * obtained by calling {@link LoggerFinder#getLogger(java.lang.String,
    1679      * java.lang.Module) LoggerFinder.getLogger(name, module)}, where
    1680      * {@code module} is the caller's module.
    1681      * In cases where {@code System.getLogger} is called from a context where
    1682      * there is no caller frame on the stack (e.g when called directly
    1683      * from a JNI attached thread), {@code IllegalCallerException} is thrown.
    1684      * To obtain a logger in such a context, use an auxiliary class that will
    1685      * implicitly be identified as the caller, or use the system {@link
    1686      * LoggerFinder#getLoggerFinder() LoggerFinder} to obtain a logger instead.
    1687      * Note that doing the latter may eagerly initialize the underlying
    1688      * logging system.
    1689      *
    1690      * @apiNote
    1691      * This method may defer calling the {@link
    1692      * LoggerFinder#getLogger(java.lang.String, java.lang.Module)
    1693      * LoggerFinder.getLogger} method to create an actual logger supplied by
    1694      * the logging backend, for instance, to allow loggers to be obtained during
    1695      * the system initialization time.
    1696      *
    1697      * @param name the name of the logger.
    1698      * @return an instance of {@link Logger} that can be used by the calling
    1699      *         class.
    1700      * @throws NullPointerException if {@code name} is {@code null}.
    1701      * @throws IllegalCallerException if there is no Java caller frame on the
    1702      *         stack.
    1703      *
    1704      * @since 9
    1705      */
    1706     @CallerSensitive
    1707     public static Logger getLogger(String name) {
    1708         Objects.requireNonNull(name);
    1709         final Class<?> caller = Reflection.getCallerClass();
    1710         if (caller == null) {
    1711             throw new IllegalCallerException("no caller frame");
    1712         }
    1713         return LazyLoggers.getLogger(name, caller.getModule());
    1714     }
    1715
    1716     /**
    1717      * Returns a localizable instance of {@link Logger
    1718      * Logger} for the caller's use.
    1719      * The returned logger will use the provided resource bundle for message
    1720      * localization.
    1721      *
    1722      * @implSpec
    1723      * The returned logger will perform message localization as specified
    1724      * by {@link LoggerFinder#getLocalizedLogger(java.lang.String,
    1725      * java.util.ResourceBundle, java.lang.Module)
    1726      * LoggerFinder.getLocalizedLogger(name, bundle, module)}, where
    1727      * {@code module} is the caller's module.
    1728      * In cases where {@code System.getLogger} is called from a context where
    1729      * there is no caller frame on the stack (e.g when called directly
    1730      * from a JNI attached thread), {@code IllegalCallerException} is thrown.
    1731      * To obtain a logger in such a context, use an auxiliary class that
    1732      * will implicitly be identified as the caller, or use the system {@link
    1733      * LoggerFinder#getLoggerFinder() LoggerFinder} to obtain a logger instead.
    1734      * Note that doing the latter may eagerly initialize the underlying
    1735      * logging system.
    1736      *
    1737      * @apiNote
    1738      * This method is intended to be used after the system is fully initialized.
    1739      * This method may trigger the immediate loading and initialization
    1740      * of the {@link LoggerFinder} service, which may cause issues if the
    1741      * Java Runtime is not ready to initialize the concrete service
    1742      * implementation yet.
    1743      * System classes which may be loaded early in the boot sequence and
    1744      * need to log localized messages should create a logger using
    1745      * {@link #getLogger(java.lang.String)} and then use the log methods that
    1746      * take a resource bundle as parameter.
    1747      *
    1748      * @param name    the name of the logger.
    1749      * @param bundle  a resource bundle.
    1750      * @return an instance of {@link Logger} which will use the provided
    1751      * resource bundle for message localization.
    1752      * @throws NullPointerException if {@code name} is {@code null} or
    1753      *         {@code bundle} is {@code null}.
    1754      * @throws IllegalCallerException if there is no Java caller frame on the
    1755      *         stack.
    1756      *
    1757      * @since 9
    1758      */
    1759     @CallerSensitive
    1760     public static Logger getLogger(String name, ResourceBundle bundle) {
    1761         final ResourceBundle rb = Objects.requireNonNull(bundle);
    1762         Objects.requireNonNull(name);
    1763         final Class<?> caller = Reflection.getCallerClass();
    1764         if (caller == null) {
    1765             throw new IllegalCallerException("no caller frame");
    1766         }
    1767         final SecurityManager sm = System.getSecurityManager();
    1768         // We don't use LazyLoggers if a resource bundle is specified.
    1769         // Bootstrap sensitive classes in the JDK do not use resource bundles
    1770         // when logging. This could be revisited later, if it needs to.
    1771         if (sm != null) {
    1772             final PrivilegedAction<Logger> pa =
    1773                     () -> LoggerFinder.accessProvider()
    1774                             .getLocalizedLogger(name, rb, caller.getModule());
    1775             return AccessController.doPrivileged(pa, null,
    1776                                          LoggerFinder.LOGGERFINDER_PERMISSION);
    1777         }
    1778         return LoggerFinder.accessProvider()
    1779                 .getLocalizedLogger(name, rb, caller.getModule());
    1780     }
    1781
    1782     /**
    1783      * Terminates the currently running Java Virtual Machine. The
    1784      * argument serves as a status code; by convention, a nonzero status
    1785      * code indicates abnormal termination.
    1786      * <p>
    1787      * This method calls the {@code exit} method in class
    1788      * {@code Runtime}. This method never returns normally.
    1789      * <p>
    1790      * The call {@code System.exit(n)} is effectively equivalent to
    1791      * the call:
    1792      * <blockquote><pre>
    1793      * Runtime.getRuntime().exit(n)
    1794      * </pre></blockquote>
    1795      *
    1796      * @param      status   exit status.
    1797      * @throws  SecurityException
    1798      *        if a security manager exists and its {@code checkExit}
    1799      *        method doesn't allow exit with the specified status.
    1800      * @see        java.lang.Runtime#exit(int)
    1801      */
    1802     public static void exit(int status) {
    1803         Runtime.getRuntime().exit(status);
    1804     }
    1805
    1806     /**
    1807      * Runs the garbage collector in the Java Virtual Machine.
    1808      * <p>
    1809      * Calling the {@code gc} method suggests that the Java Virtual Machine
    1810      * expend effort toward recycling unused objects in order to
    1811      * make the memory they currently occupy available for reuse
    1812      * by the Java Virtual Machine.
    1813      * When control returns from the method call, the Java Virtual Machine
    1814      * has made a best effort to reclaim space from all unused objects.
    1815      * There is no guarantee that this effort will recycle any particular
    1816      * number of unused objects, reclaim any particular amount of space, or
    1817      * complete at any particular time, if at all, before the method returns or ever.
    1818      * <p>
    1819      * The call {@code System.gc()} is effectively equivalent to the
    1820      * call:
    1821      * <blockquote><pre>
    1822      * Runtime.getRuntime().gc()
    1823      * </pre></blockquote>
    1824      *
    1825      * @see     java.lang.Runtime#gc()
    1826      */
    1827     public static void gc() {
    1828         Runtime.getRuntime().gc();
    1829     }
    1830
    1831     /**
    1832      * Runs the finalization methods of any objects pending finalization.
    1833      *
    1834      * Calling this method suggests that the Java Virtual Machine expend
    1835      * effort toward running the {@code finalize} methods of objects
    1836      * that have been found to be discarded but whose {@code finalize}
    1837      * methods have not yet been run. When control returns from the
    1838      * method call, the Java Virtual Machine has made a best effort to
    1839      * complete all outstanding finalizations.
    1840      * <p>
    1841      * The call {@code System.runFinalization()} is effectively
    1842      * equivalent to the call:
    1843      * <blockquote><pre>
    1844      * Runtime.getRuntime().runFinalization()
    1845      * </pre></blockquote>
    1846      *
    1847      * @see     java.lang.Runtime#runFinalization()
    1848      */
    1849     public static void runFinalization() {
    1850         Runtime.getRuntime().runFinalization();
    1851     }
    1852
    1853     /**
    1854      * Loads the native library specified by the filename argument.  The filename
    1855      * argument must be an absolute path name.
    1856      *
    1857      * If the filename argument, when stripped of any platform-specific library
    1858      * prefix, path, and file extension, indicates a library whose name is,
    1859      * for example, L, and a native library called L is statically linked
    1860      * with the VM, then the JNI_OnLoad_L function exported by the library
    1861      * is invoked rather than attempting to load a dynamic library.
    1862      * A filename matching the argument does not have to exist in the
    1863      * file system.
    1864      * See the <a href="{@docRoot}/../specs/jni/index.html"> JNI Specification</a>
    1865      * for more details.
    1866      *
    1867      * Otherwise, the filename argument is mapped to a native library image in
    1868      * an implementation-dependent manner.
    1869      *
    1870      * <p>
    1871      * The call {@code System.load(name)} is effectively equivalent
    1872      * to the call:
    1873      * <blockquote><pre>
    1874      * Runtime.getRuntime().load(name)
    1875      * </pre></blockquote>
    1876      *
    1877      * @param      filename   the file to load.
    1878      * @throws     SecurityException  if a security manager exists and its
    1879      *             {@code checkLink} method doesn't allow
    1880      *             loading of the specified dynamic library
    1881      * @throws     UnsatisfiedLinkError  if either the filename is not an
    1882      *             absolute path name, the native library is not statically
    1883      *             linked with the VM, or the library cannot be mapped to
    1884      *             a native library image by the host system.
    1885      * @throws     NullPointerException if {@code filename} is {@code null}
    1886      * @see        java.lang.Runtime#load(java.lang.String)
    1887      * @see        java.lang.SecurityManager#checkLink(java.lang.String)
    1888      */
    1889     @CallerSensitive
    1890     public static void load(String filename) {
    1891         Runtime.getRuntime().load0(Reflection.getCallerClass(), filename);
    1892     }
    1893
    1894     /**
    1895      * Loads the native library specified by the {@code libname}
    1896      * argument.  The {@code libname} argument must not contain any platform
    1897      * specific prefix, file extension or path. If a native library
    1898      * called {@code libname} is statically linked with the VM, then the
    1899      * JNI_OnLoad_{@code libname} function exported by the library is invoked.
    1900      * See the <a href="{@docRoot}/../specs/jni/index.html"> JNI Specification</a>
    1901      * for more details.
    1902      *
    1903      * Otherwise, the libname argument is loaded from a system library
    1904      * location and mapped to a native library image in an
    1905      * implementation-dependent manner.
    1906      * <p>
    1907      * The call {@code System.loadLibrary(name)} is effectively
    1908      * equivalent to the call
    1909      * <blockquote><pre>
    1910      * Runtime.getRuntime().loadLibrary(name)
    1911      * </pre></blockquote>
    1912      *
    1913      * @param      libname   the name of the library.
    1914      * @throws     SecurityException  if a security manager exists and its
    1915      *             {@code checkLink} method doesn't allow
    1916      *             loading of the specified dynamic library
    1917      * @throws     UnsatisfiedLinkError if either the libname argument
    1918      *             contains a file path, the native library is not statically
    1919      *             linked with the VM,  or the library cannot be mapped to a
    1920      *             native library image by the host system.
    1921      * @throws     NullPointerException if {@code libname} is {@code null}
    1922      * @see        java.lang.Runtime#loadLibrary(java.lang.String)
    1923      * @see        java.lang.SecurityManager#checkLink(java.lang.String)
    1924      */
    1925     @CallerSensitive
    1926     public static void loadLibrary(String libname) {
    1927         Runtime.getRuntime().loadLibrary0(Reflection.getCallerClass(), libname);
    1928     }
    1929
    1930     /**
    1931      * Maps a library name into a platform-specific string representing
    1932      * a native library.
    1933      *
    1934      * @param      libname the name of the library.
    1935      * @return     a platform-dependent native library name.
    1936      * @throws     NullPointerException if {@code libname} is {@code null}
    1937      * @see        java.lang.System#loadLibrary(java.lang.String)
    1938      * @see        java.lang.ClassLoader#findLibrary(java.lang.String)
    1939      * @since      1.2
    1940      */
    1941     public static native String mapLibraryName(String libname);
    1942
    1943     /**
    1944      * Create PrintStream for stdout/err based on encoding.
    1945      */
    1946     private static PrintStream newPrintStream(FileOutputStream fos, String enc) {
    1947        if (enc != null) {
    1948             try {
    1949                 return new PrintStream(new BufferedOutputStream(fos, 128), true, enc);
    1950             } catch (UnsupportedEncodingException uee) {}
    1951         }
    1952         return new PrintStream(new BufferedOutputStream(fos, 128), true);
    1953     }
    1954
    1955     /**
    1956      * Logs an exception/error at initialization time to stdout or stderr.
    1957      *
    1958      * @param printToStderr to print to stderr rather than stdout
    1959      * @param printStackTrace to print the stack trace
    1960      * @param msg the message to print before the exception, can be {@code null}
    1961      * @param e the exception or error
    1962      */
    1963     private static void logInitException(boolean printToStderr,
    1964                                          boolean printStackTrace,
    1965                                          String msg,
    1966                                          Throwable e) {
    1967         if (VM.initLevel() < 1) {
    1968             throw new InternalError("system classes not initialized");
    1969         }
    1970         PrintStream log = (printToStderr) ? err : out;
    1971         if (msg != null) {
    1972             log.println(msg);
    1973         }
    1974         if (printStackTrace) {
    1975             e.printStackTrace(log);
    1976         } else {
    1977             log.println(e);
    1978             for (Throwable suppressed : e.getSuppressed()) {
    1979                 log.println("Suppressed: " + suppressed);
    1980             }
    1981             Throwable cause = e.getCause();
    1982             if (cause != null) {
    1983                 log.println("Caused by: " + cause);
    1984             }
    1985         }
    1986     }
    1987
    1988     /**
    1989      * Create the Properties object from a map - masking out system properties
    1990      * that are not intended for public access.
    1991      */
    1992     private static Properties createProperties(Map<String, String> initialProps) {
    1993         Properties properties = new Properties(initialProps.size());
    1994         for (var entry : initialProps.entrySet()) {
    1995             String prop = entry.getKey();
    1996             switch (prop) {
    1997                 // Do not add private system properties to the Properties
    1998                 case "sun.nio.MaxDirectMemorySize":
    1999                 case "sun.nio.PageAlignDirectMemory":
    2000                     // used by java.lang.Integer.IntegerCache
    2001                 case "java.lang.Integer.IntegerCache.high":
    2002                     // used by sun.launcher.LauncherHelper
    2003                 case "sun.java.launcher.diag":
    2004                     // used by jdk.internal.loader.ClassLoaders
    2005                 case "jdk.boot.class.path.append":
    2006                     break;
    2007                 default:
    2008                     properties.put(prop, entry.getValue());
    2009             }
    2010         }
    2011         return properties;
    2012     }
    2013
    2014     /**
    2015      * Initialize the system class.  Called after thread initialization.
    2016      */
    2017     private static void initPhase1() {
    2018
    2019         // register the shared secrets - do this first, since SystemProps.initProperties
    2020         // might initialize CharsetDecoders that rely on it
    2021         setJavaLangAccess();
    2022
    2023         // VM might invoke JNU_NewStringPlatform() to set those encoding
    2024         // sensitive properties (user.home, user.name, boot.class.path, etc.)
    2025         // during "props" initialization.
    2026         // The charset is initialized in System.c and does not depend on the Properties.
    2027         Map<String, String> tempProps = SystemProps.initProperties();
    2028         VersionProps.init(tempProps);
    2029
    2030         // There are certain system configurations that may be controlled by
    2031         // VM options such as the maximum amount of direct memory and
    2032         // Integer cache size used to support the object identity semantics
    2033         // of autoboxing.  Typically, the library will obtain these values
    2034         // from the properties set by the VM.  If the properties are for
    2035         // internal implementation use only, these properties should be
    2036         // masked from the system properties.
    2037         //
    2038         // Save a private copy of the system properties object that
    2039         // can only be accessed by the internal implementation.
    2040         VM.saveProperties(tempProps);
    2041         props = createProperties(tempProps);
    2042
    2043         StaticProperty.javaHome();          // Load StaticProperty to cache the property values
    2044
    2045         lineSeparator = props.getProperty("line.separator");
    2046
    2047         FileInputStream fdIn = new FileInputStream(FileDescriptor.in);
    2048         FileOutputStream fdOut = new FileOutputStream(FileDescriptor.out);
    2049         FileOutputStream fdErr = new FileOutputStream(FileDescriptor.err);
    2050         setIn0(new BufferedInputStream(fdIn));
    2051         // sun.stdout/err.encoding are set when the VM is associated with the terminal,
    2052         // thus they are equivalent to Console.charset(), otherwise the encoding
    2053         // defaults to Charset.defaultCharset()
    2054         setOut0(newPrintStream(fdOut, props.getProperty("sun.stdout.encoding")));
    2055         setErr0(newPrintStream(fdErr, props.getProperty("sun.stderr.encoding")));
    2056
    2057         // Setup Java signal handlers for HUP, TERM, and INT (where available).
    2058         Terminator.setup();
    2059
    2060         // Initialize any miscellaneous operating system settings that need to be
    2061         // set for the class libraries. Currently this is no-op everywhere except
    2062         // for Windows where the process-wide error mode is set before the java.io
    2063         // classes are used.
    2064         VM.initializeOSEnvironment();
    2065
    2066         // The main thread is not added to its thread group in the same
    2067         // way as other threads; we must do it ourselves here.
    2068         Thread current = Thread.currentThread();
    2069         current.getThreadGroup().add(current);
    2070
    2071
    2072         // Subsystems that are invoked during initialization can invoke
    2073         // VM.isBooted() in order to avoid doing things that should
    2074         // wait until the VM is fully initialized. The initialization level
    2075         // is incremented from 0 to 1 here to indicate the first phase of
    2076         // initialization has completed.
    2077         // IMPORTANT: Ensure that this remains the last initialization action!
    2078         VM.initLevel(1);
    2079     }
    2080
    2081     // @see #initPhase2()
    2082     static ModuleLayer bootLayer;
    2083
    2084     /*
    2085      * Invoked by VM.  Phase 2 module system initialization.
    2086      * Only classes in java.base can be loaded in this phase.
    2087      *
    2088      * @param printToStderr print exceptions to stderr rather than stdout
    2089      * @param printStackTrace print stack trace when exception occurs
    2090      *
    2091      * @return JNI_OK for success, JNI_ERR for failure
    2092      */
    2093     private static int initPhase2(boolean printToStderr, boolean printStackTrace) {
    2094
    2095         try {
    2096             bootLayer = ModuleBootstrap.boot();
    2097         } catch (Exception | Error e) {
    2098             logInitException(printToStderr, printStackTrace,
    2099                              "Error occurred during initialization of boot layer", e);
    2100             return -1; // JNI_ERR
    2101         }
    2102
    2103         // module system initialized
    2104         VM.initLevel(2);
    2105
    2106         return 0; // JNI_OK
    2107     }
    2108
    2109     /*
    2110      * Invoked by VM.  Phase 3 is the final system initialization:
    2111      * 1. eagerly initialize bootstrap method factories that might interact
    2112      *    negatively with custom security managers and custom class loaders
    2113      * 2. set security manager
    2114      * 3. set system class loader
    2115      * 4. set TCCL
    2116      *
    2117      * This method must be called after the module system initialization.
    2118      * The security manager and system class loader may be a custom class from
    2119      * the application classpath or modulepath.
    2120      */
    2121     private static void initPhase3() {
    2122
    2123         // Initialize the StringConcatFactory eagerly to avoid potential
    2124         // bootstrap circularity issues that could be caused by a custom
    2125         // SecurityManager
    2126         Unsafe.getUnsafe().ensureClassInitialized(StringConcatFactory.class);
    2127
    2128         String smProp = System.getProperty("java.security.manager");
    2129         if (smProp != null) {
    2130             switch (smProp) {
    2131                 case "disallow":
    2132                     allowSecurityManager = NEVER;
    2133                     break;
    2134                 case "allow":
    2135                     allowSecurityManager = MAYBE;
    2136                     break;
    2137                 case "":
    2138                 case "default":
    2139                     setSecurityManager(new SecurityManager());
    2140                     allowSecurityManager = MAYBE;
    2141                     break;
    2142                 default:
    2143                     try {
    2144                         ClassLoader cl = ClassLoader.getBuiltinAppClassLoader();
    2145                         Class<?> c = Class.forName(smProp, false, cl);
    2146                         Constructor<?> ctor = c.getConstructor();
    2147                         // Must be a public subclass of SecurityManager with
    2148                         // a public no-arg constructor
    2149                         if (!SecurityManager.class.isAssignableFrom(c) ||
    2150                             !Modifier.isPublic(c.getModifiers()) ||
    2151                             !Modifier.isPublic(ctor.getModifiers())) {
    2152                             throw new Error("Could not create SecurityManager: "
    2153                                              + ctor.toString());
    2154                         }
    2155                         // custom security manager may be in non-exported package
    2156                         ctor.setAccessible(true);
    2157                         SecurityManager sm = (SecurityManager) ctor.newInstance();
    2158                         setSecurityManager(sm);
    2159                     } catch (Exception e) {
    2160                         throw new InternalError("Could not create SecurityManager", e);
    2161                     }
    2162                     allowSecurityManager = MAYBE;
    2163             }
    2164         } else {
    2165             allowSecurityManager = NEVER;
    2166         }
    2167
    2168         if (allowSecurityManager != NEVER) {
    2169             System.err.println("WARNING: The Security Manager is deprecated" +
    2170                     " and will be removed in a future release.");
    2171         }
    2172
    2173         // initializing the system class loader
    2174         VM.initLevel(3);
    2175
    2176         // system class loader initialized
    2177         ClassLoader scl = ClassLoader.initSystemClassLoader();
    2178
    2179         // set TCCL
    2180         Thread.currentThread().setContextClassLoader(scl);
    2181
    2182         // system is fully initialized
    2183         VM.initLevel(4);
    2184     }
    2185
    2186     private static void setJavaLangAccess() {
    2187         // Allow privileged classes outside of java.lang
    2188         SharedSecrets.setJavaLangAccess(new JavaLangAccess() {
    2189             public List<Method> getDeclaredPublicMethods(Class<?> klass, String name, Class<?>... parameterTypes) {
    2190                 return klass.getDeclaredPublicMethods(name, parameterTypes);
    2191             }
    2192             public jdk.internal.reflect.ConstantPool getConstantPool(Class<?> klass) {
    2193                 return klass.getConstantPool();
    2194             }
    2195             public boolean casAnnotationType(Class<?> klass, AnnotationType oldType, AnnotationType newType) {
    2196                 return klass.casAnnotationType(oldType, newType);
    2197             }
    2198             public AnnotationType getAnnotationType(Class<?> klass) {
    2199                 return klass.getAnnotationType();
    2200             }
    2201             public Map<Class<? extends Annotation>, Annotation> getDeclaredAnnotationMap(Class<?> klass) {
    2202                 return klass.getDeclaredAnnotationMap();
    2203             }
    2204             public byte[] getRawClassAnnotations(Class<?> klass) {
    2205                 return klass.getRawAnnotations();
    2206             }
    2207             public byte[] getRawClassTypeAnnotations(Class<?> klass) {
    2208                 return klass.getRawTypeAnnotations();
    2209             }
    2210             public byte[] getRawExecutableTypeAnnotations(Executable executable) {
    2211                 return Class.getExecutableTypeAnnotationBytes(executable);
    2212             }
    2213             public <E extends Enum<E>>
    2214             E[] getEnumConstantsShared(Class<E> klass) {
    2215                 return klass.getEnumConstantsShared();
    2216             }
    2217             public void blockedOn(Interruptible b) {
    2218                 Thread.blockedOn(b);
    2219             }
    2220             public void registerShutdownHook(int slot, boolean registerShutdownInProgress, Runnable hook) {
    2221                 Shutdown.add(slot, registerShutdownInProgress, hook);
    2222             }
    2223             public Thread newThreadWithAcc(Runnable target, AccessControlContext acc) {
    2224                 return new Thread(target, acc);
    2225             }
    2226             @SuppressWarnings("deprecation")
    2227             public void invokeFinalize(Object o) throws Throwable {
    2228                 o.finalize();
    2229             }
    2230             public ConcurrentHashMap<?, ?> createOrGetClassLoaderValueMap(ClassLoader cl) {
    2231                 return cl.createOrGetClassLoaderValueMap();
    2232             }
    2233             public Class<?> defineClass(ClassLoader loader, String name, byte[] b, ProtectionDomain pd, String source) {
    2234                 return ClassLoader.defineClass1(loader, name, b, 0, b.length, pd, source);
    2235             }
    2236             public Class<?> defineClass(ClassLoader loader, Class<?> lookup, String name, byte[] b, ProtectionDomain pd,
    2237                                         boolean initialize, int flags, Object classData) {
    2238                 return ClassLoader.defineClass0(loader, lookup, name, b, 0, b.length, pd, initialize, flags, classData);
    2239             }
    2240             public Class<?> findBootstrapClassOrNull(String name) {
    2241                 return ClassLoader.findBootstrapClassOrNull(name);
    2242             }
    2243             public Package definePackage(ClassLoader cl, String name, Module module) {
    2244                 return cl.definePackage(name, module);
    2245             }
    2246             public String fastUUID(long lsb, long msb) {
    2247                 return Long.fastUUID(lsb, msb);
    2248             }
    2249             public void addNonExportedPackages(ModuleLayer layer) {
    2250                 SecurityManager.addNonExportedPackages(layer);
    2251             }
    2252             public void invalidatePackageAccessCache() {
    2253                 SecurityManager.invalidatePackageAccessCache();
    2254             }
    2255             public Module defineModule(ClassLoader loader,
    2256                                        ModuleDescriptor descriptor,
    2257                                        URI uri) {
    2258                 return new Module(null, loader, descriptor, uri);
    2259             }
    2260             public Module defineUnnamedModule(ClassLoader loader) {
    2261                 return new Module(loader);
    2262             }
    2263             public void addReads(Module m1, Module m2) {
    2264                 m1.implAddReads(m2);
    2265             }
    2266             public void addReadsAllUnnamed(Module m) {
    2267                 m.implAddReadsAllUnnamed();
    2268             }
    2269             public void addExports(Module m, String pn) {
    2270                 m.implAddExports(pn);
    2271             }
    2272             public void addExports(Module m, String pn, Module other) {
    2273                 m.implAddExports(pn, other);
    2274             }
    2275             public void addExportsToAllUnnamed(Module m, String pn) {
    2276                 m.implAddExportsToAllUnnamed(pn);
    2277             }
    2278             public void addOpens(Module m, String pn, Module other) {
    2279                 m.implAddOpens(pn, other);
    2280             }
    2281             public void addOpensToAllUnnamed(Module m, String pn) {
    2282                 m.implAddOpensToAllUnnamed(pn);
    2283             }
    2284             public void addOpensToAllUnnamed(Module m, Set<String> concealedPackages, Set<String> exportedPackages) {
    2285                 m.implAddOpensToAllUnnamed(concealedPackages, exportedPackages);
    2286             }
    2287             public void addUses(Module m, Class<?> service) {
    2288                 m.implAddUses(service);
    2289             }
    2290             public boolean isReflectivelyExported(Module m, String pn, Module other) {
    2291                 return m.isReflectivelyExported(pn, other);
    2292             }
    2293             public boolean isReflectivelyOpened(Module m, String pn, Module other) {
    2294                 return m.isReflectivelyOpened(pn, other);
    2295             }
    2296             public ServicesCatalog getServicesCatalog(ModuleLayer layer) {
    2297                 return layer.getServicesCatalog();
    2298             }
    2299             public void bindToLoader(ModuleLayer layer, ClassLoader loader) {
    2300                 layer.bindToLoader(loader);
    2301             }
    2302             public Stream<ModuleLayer> layers(ModuleLayer layer) {
    2303                 return layer.layers();
    2304             }
    2305             public Stream<ModuleLayer> layers(ClassLoader loader) {
    2306                 return ModuleLayer.layers(loader);
    2307             }
    2308
    2309             public String newStringNoRepl(byte[] bytes, Charset cs) throws CharacterCodingException  {
    2310                 return String.newStringNoRepl(bytes, cs);
    2311             }
    2312
    2313             public byte[] getBytesNoRepl(String s, Charset cs) throws CharacterCodingException {
    2314                 return String.getBytesNoRepl(s, cs);
    2315             }
    2316
    2317             public String newStringUTF8NoRepl(byte[] bytes, int off, int len) {
    2318                 return String.newStringUTF8NoRepl(bytes, off, len);
    2319             }
    2320
    2321             public byte[] getBytesUTF8NoRepl(String s) {
    2322                 return String.getBytesUTF8NoRepl(s);
    2323             }
    2324
    2325             public void inflateBytesToChars(byte[] src, int srcOff, char[] dst, int dstOff, int len) {
    2326                 StringLatin1.inflate(src, srcOff, dst, dstOff, len);
    2327             }
    2328
    2329             public int decodeASCII(byte[] src, int srcOff, char[] dst, int dstOff, int len) {
    2330                 return String.decodeASCII(src, srcOff, dst, dstOff, len);
    2331             }
    2332
    2333             public void setCause(Throwable t, Throwable cause) {
    2334                 t.setCause(cause);
    2335             }
    2336
    2337             public ProtectionDomain protectionDomain(Class<?> c) {
    2338                 return c.protectionDomain();
    2339             }
    2340
    2341             public MethodHandle stringConcatHelper(String name, MethodType methodType) {
    2342                 return StringConcatHelper.lookupStatic(name, methodType);
    2343             }
    2344
    2345             public long stringConcatInitialCoder() {
    2346                 return StringConcatHelper.initialCoder();
    2347             }
    2348
    2349             public long stringConcatMix(long lengthCoder, String constant) {
    2350                 return StringConcatHelper.mix(lengthCoder, constant);
    2351             }
    2352
    2353             public String join(String prefix, String suffix, String delimiter, String[] elements, int size) {
    2354                 return String.join(prefix, suffix, delimiter, elements, size);
    2355             }
    2356
    2357             public Object classData(Class<?> c) {
    2358                 return c.getClassData();
    2359             }
    2360         });
    2361     }
    2362 }